class SSHData::PublicKey::Base

Attributes

algo[R]

Public Class Methods

new(**kwargs) click to toggle source
# File lib/ssh_data/public_key/base.rb, line 6
def initialize(**kwargs)
  @algo = kwargs[:algo]
end

Public Instance Methods

==(other) click to toggle source

Is this public key equal to another public key?

other - Another SSHData::PublicKey::Base instance to compare with.

Returns boolean.

# File lib/ssh_data/public_key/base.rb, line 66
def ==(other)
  other.class == self.class
end
fingerprint(md5: false) click to toggle source

Calculate the fingerprint of this public key.

md5: - Bool of whether to generate an MD5 fingerprint instead of the

default SHA256.

Returns a String fingerprint.

# File lib/ssh_data/public_key/base.rb, line 16
def fingerprint(md5: false)
  if md5
    # colon separated, hex encoded md5 digest
    OpenSSL::Digest::MD5.digest(rfc4253).unpack("H2" * 16).join(":")
  else
    # base64 encoded sha256 digest with b64 padding stripped
    Base64.strict_encode64(OpenSSL::Digest::SHA256.digest(rfc4253))[0...-1]
  end
end
openssh(comment: nil) click to toggle source

OpenSSH public key in authorized_keys format (see sshd(8) manual page).

comment - Optional String comment to append.

Returns a String key.

# File lib/ssh_data/public_key/base.rb, line 57
def openssh(comment: nil)
  [algo, Base64.strict_encode64(rfc4253), comment].compact.join(" ")
end
rfc4253() click to toggle source

RFC4253 binary encoding of the public key.

Returns a binary String.

# File lib/ssh_data/public_key/base.rb, line 48
def rfc4253
  raise "implement me"
end
sign(signed_data) click to toggle source

Make an SSH signature.

signed_data - The String message over which to calculated the signature.

Returns a binary String signature.

# File lib/ssh_data/public_key/base.rb, line 31
def sign(signed_data)
  raise "implement me"
end
verify(signed_data, signature) click to toggle source

Verify an SSH signature.

signed_data - The String message that the signature was calculated over. signature - The binary String signature with SSH encoding.

Returns boolean.

# File lib/ssh_data/public_key/base.rb, line 41
def verify(signed_data, signature)
  raise "implement me"
end