Module: SSHData

Extended by:
SSHData
Included in:
SSHData
Defined in:
lib/ssh_data.rb,
lib/ssh_data/error.rb,
lib/ssh_data/version.rb,
lib/ssh_data/encoding.rb,
lib/ssh_data/public_key.rb,
lib/ssh_data/certificate.rb,
lib/ssh_data/private_key.rb,
lib/ssh_data/public_key/dsa.rb,
lib/ssh_data/public_key/rsa.rb,
lib/ssh_data/private_key/dsa.rb,
lib/ssh_data/private_key/rsa.rb,
lib/ssh_data/public_key/base.rb,
lib/ssh_data/private_key/base.rb,
lib/ssh_data/public_key/ecdsa.rb,
lib/ssh_data/private_key/ecdsa.rb,
lib/ssh_data/public_key/ed25519.rb,
lib/ssh_data/private_key/ed25519.rb

Defined Under Namespace

Modules: Encoding, PrivateKey, PublicKey Classes: Certificate

Constant Summary collapse

Error =
Class.new(StandardError)
DecodeError =
Class.new(Error)
VerifyError =
Class.new(Error)
AlgorithmError =
Class.new(Error)
DecryptError =
Class.new(Error)
VERSION =
"1.1.0"

Instance Method Summary collapse

Instance Method Details

#key_parts(key) ⇒ Object

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.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ssh_data.rb', line 13

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