Class: SSHData::PublicKey::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_data/public_key/base.rb

Direct Known Subclasses

DSA, ECDSA, ED25519, RSA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/ssh_data/public_key/base.rb', line 6

def initialize(**kwargs)
  @algo = kwargs[:algo]
end

Instance Attribute Details

#algoObject (readonly)

Returns the value of attribute algo.



4
5
6
# File 'lib/ssh_data/public_key/base.rb', line 4

def algo
  @algo
end

Instance Method Details

#==(other) ⇒ Object

Is this public key equal to another public key?

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

Returns boolean.



66
67
68
# File 'lib/ssh_data/public_key/base.rb', line 66

def ==(other)
  other.class == self.class
end

#fingerprint(md5: false) ⇒ Object

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.



16
17
18
19
20
21
22
23
24
# 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) ⇒ Object

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

comment - Optional String comment to append.

Returns a String key.



57
58
59
# File 'lib/ssh_data/public_key/base.rb', line 57

def openssh(comment: nil)
  [algo, Base64.strict_encode64(rfc4253), comment].compact.join(" ")
end

#rfc4253Object

RFC4253 binary encoding of the public key.

Returns a binary String.



48
49
50
# File 'lib/ssh_data/public_key/base.rb', line 48

def rfc4253
  raise "implement me"
end

#sign(signed_data) ⇒ Object

Make an SSH signature.

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

Returns a binary String signature.



31
32
33
# File 'lib/ssh_data/public_key/base.rb', line 31

def sign(signed_data)
  raise "implement me"
end

#verify(signed_data, signature) ⇒ Object

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.



41
42
43
# File 'lib/ssh_data/public_key/base.rb', line 41

def verify(signed_data, signature)
  raise "implement me"
end