File: ssh_data.rb

package info (click to toggle)
ruby-ssh-data 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 184 kB
  • sloc: ruby: 1,483; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require "openssl"
require "base64"

module SSHData
  # Break down a key in OpenSSH authorized_keys format (see sshd(8) manual
  # page).
  #
  # key - An OpenSSH formatted public key or certificate, including algo,
  #       base64 encoded key and optional comment.
  #
  # Returns an Array containing the algorithm String , the raw key or
  # certificate String and the comment String or nil.
  def key_parts(key)
    algo, b64, comment = key.strip.split(" ", 3)
    if algo.nil? || b64.nil?
      raise DecodeError, "bad data format"
    end

    raw = begin
      Base64.strict_decode64(b64)
    rescue ArgumentError
      raise DecodeError, "bad data format"
    end

    [algo, raw, comment]
  end

  extend self
end

require "ssh_data/version"
require "ssh_data/error"
require "ssh_data/certificate"
require "ssh_data/public_key"
require "ssh_data/private_key"
require "ssh_data/encoding"
require "ssh_data/signature"