Class: SSHData::PublicKey::ED25519
- Defined in:
- lib/ssh_data/public_key/ed25519.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ed25519_key ⇒ Object
readonly
Returns the value of attribute ed25519_key.
-
#pk ⇒ Object
readonly
Returns the value of attribute pk.
Attributes inherited from Base
Class Method Summary collapse
- .algorithm_identifier ⇒ Object
-
.ed25519_gem_required! ⇒ Object
Assert that the ed25519 gem has been loaded.
-
.enabled? ⇒ Boolean
ed25519 isn’t a hard requirement for using this Gem.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Is this public key equal to another public key?.
-
#initialize(algo:, pk:) ⇒ ED25519
constructor
A new instance of ED25519.
-
#rfc4253 ⇒ Object
RFC4253 binary encoding of the public key.
-
#verify(signed_data, signature) ⇒ Object
Verify an SSH signature.
Methods inherited from Base
Constructor Details
#initialize(algo:, pk:) ⇒ ED25519
Returns a new instance of ED25519.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#ed25519_key ⇒ Object (readonly)
Returns the value of attribute ed25519_key.
4 5 6 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 4 def ed25519_key @ed25519_key end |
#pk ⇒ Object (readonly)
Returns the value of attribute pk.
4 5 6 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 4 def pk @pk end |
Class Method Details
.algorithm_identifier ⇒ Object
19 20 21 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 19 def self.algorithm_identifier ALGO_ED25519 end |
.ed25519_gem_required! ⇒ Object
Assert that the ed25519 gem has been loaded.
Returns nothing, raises AlgorithmError.
15 16 17 |
# 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? ⇒ Boolean
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.
8 9 10 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 8 def self.enabled? Object.const_defined?(:Ed25519) 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.
73 74 75 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 73 def ==(other) super && other.pk == pk end |
#rfc4253 ⇒ Object
RFC4253 binary encoding of the public key.
Returns a binary String.
61 62 63 64 65 66 |
# File 'lib/ssh_data/public_key/ed25519.rb', line 61 def rfc4253 Encoding.encode_fields( [:string, algo], [:string, pk], ) 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 |