Class: SSHData::PrivateKey::ED25519
- Defined in:
- lib/ssh_data/private_key/ed25519.rb
Instance Attribute Summary collapse
-
#ed25519_key ⇒ Object
readonly
Returns the value of attribute ed25519_key.
-
#pk ⇒ Object
readonly
Returns the value of attribute pk.
-
#sk ⇒ Object
readonly
Returns the value of attribute sk.
Attributes inherited from Base
Class Method Summary collapse
-
.from_ed25519(key) ⇒ Object
Create from a ::Ed25519::SigningKey instance.
-
.generate ⇒ Object
Generate a new private key.
Instance Method Summary collapse
-
#initialize(algo:, pk:, sk:, comment:) ⇒ ED25519
constructor
A new instance of ED25519.
-
#sign(signed_data, algo: nil) ⇒ Object
Make an SSH signature.
Methods inherited from Base
Constructor Details
#initialize(algo:, pk:, sk:, comment:) ⇒ ED25519
Returns a new instance of ED25519.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ssh_data/private_key/ed25519.rb', line 28 def initialize(algo:, pk:, sk:, comment:) unless algo == PublicKey::ALGO_ED25519 raise DecodeError, "bad algorithm: #{algo.inspect}" end # openssh stores the pk twice, once as half of the sk... if sk.bytesize != 64 || sk.byteslice(32, 32) != pk raise DecodeError, "bad sk" end @pk = pk @sk = sk super(algo: algo, comment: comment) if PublicKey::ED25519.enabled? @ed25519_key = Ed25519::SigningKey.new(sk.byteslice(0, 32)) if @ed25519_key.verify_key.to_bytes != pk raise DecodeError, "bad pk" end end @public_key = PublicKey::ED25519.new(algo: algo, pk: pk) end |
Instance Attribute Details
#ed25519_key ⇒ Object (readonly)
Returns the value of attribute ed25519_key.
4 5 6 |
# File 'lib/ssh_data/private_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/private_key/ed25519.rb', line 4 def pk @pk end |
#sk ⇒ Object (readonly)
Returns the value of attribute sk.
4 5 6 |
# File 'lib/ssh_data/private_key/ed25519.rb', line 4 def sk @sk end |
Class Method Details
.from_ed25519(key) ⇒ Object
Create from a ::Ed25519::SigningKey instance.
key - A ::Ed25519::SigningKey instance.
Returns a ED25519 instance.
19 20 21 22 23 24 25 26 |
# File 'lib/ssh_data/private_key/ed25519.rb', line 19 def self.from_ed25519(key) new( algo: PublicKey::ALGO_ED25519, pk: key.verify_key.to_bytes, sk: key.to_bytes + key.verify_key.to_bytes, comment: "", ) end |
.generate ⇒ Object
Generate a new private key.
Returns a PublicKey::Base subclass instance.
9 10 11 12 |
# File 'lib/ssh_data/private_key/ed25519.rb', line 9 def self.generate PublicKey::ED25519.ed25519_gem_required! from_ed25519(Ed25519::SigningKey.generate) end |
Instance Method Details
#sign(signed_data, algo: nil) ⇒ Object
Make an SSH signature.
signed_data - The String message over which to calculated the signature.
Returns a binary String signature.
59 60 61 62 63 64 65 |
# File 'lib/ssh_data/private_key/ed25519.rb', line 59 def sign(signed_data, algo: nil) PublicKey::ED25519.ed25519_gem_required! algo ||= self.algo raise AlgorithmError unless algo == self.algo raw_sig = ed25519_key.sign(signed_data) Encoding.encode_signature(algo, raw_sig) end |