class SSHData::PublicKey::ED25519

Attributes

ed25519_key[R]
pk[R]

Public Class Methods

algorithm_identifier() click to toggle source
# File lib/ssh_data/public_key/ed25519.rb, line 19
def self.algorithm_identifier
  ALGO_ED25519
end
ed25519_gem_required!() click to toggle source

Assert that the ed25519 gem has been loaded.

Returns nothing, raises AlgorithmError.

# File lib/ssh_data/public_key/ed25519.rb, line 15
def self.ed25519_gem_required!
  raise AlgorithmError, "the ed25519 gem is not loaded" unless enabled?
end
enabled?() click to toggle source

ed25519 isn’t a hard requirement for using this Gem. We only do actual validation with the key if the ed25519 Gem has been loaded.

# File lib/ssh_data/public_key/ed25519.rb, line 8
def self.enabled?
  Object.const_defined?(:Ed25519)
end
new(algo:, pk:) click to toggle source
Calls superclass method SSHData::PublicKey::Base::new
# File lib/ssh_data/public_key/ed25519.rb, line 23
def initialize(algo:, pk:)
  unless algo == self.class.algorithm_identifier
    raise DecodeError, "bad algorithm: #{algo.inspect}"
  end

  @pk = pk

  if self.class.enabled?
    @ed25519_key = Ed25519::VerifyKey.new(pk)
  end

  super(algo: 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.

Calls superclass method SSHData::PublicKey::Base#==
# File lib/ssh_data/public_key/ed25519.rb, line 73
def ==(other)
  super && other.pk == pk
end
rfc4253() click to toggle source

RFC4253 binary encoding of the public key.

Returns a binary String.

# File lib/ssh_data/public_key/ed25519.rb, line 61
def rfc4253
  Encoding.encode_fields(
    [:string, algo],
    [:string, pk],
  )
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 binarty String signature with SSH encoding.

Returns boolean.

# File lib/ssh_data/public_key/ed25519.rb, line 43
def verify(signed_data, signature)
  self.class.ed25519_gem_required!

  sig_algo, raw_sig, _ = Encoding.decode_signature(signature)
  if sig_algo != self.class.algorithm_identifier
    raise DecodeError, "bad signature algorithm: #{sig_algo.inspect}"
  end

  begin
    ed25519_key.verify(raw_sig, signed_data)
  rescue Ed25519::VerifyError
    false
  end
end