Class: Nuckle::PublicKey
- Inherits:
-
Object
- Object
- Nuckle::PublicKey
- Defined in:
- lib/nuckle/public_key.rb
Overview
An X25519 (Curve25519) public key.
Constant Summary collapse
- BYTES =
Key length in bytes.
32
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Constant-time equality comparison.
-
#initialize(key) ⇒ PublicKey
constructor
A new instance of PublicKey.
-
#to_bytes ⇒ String
Raw 32-byte key (binary).
-
#to_s ⇒ String
Raw 32-byte key (binary).
Constructor Details
#initialize(key) ⇒ PublicKey
Returns a new instance of PublicKey.
11 12 13 14 15 16 17 |
# File 'lib/nuckle/public_key.rb', line 11 def initialize(key) key = key.to_s if key.respond_to?(:to_s) && !key.is_a?(String) key = key.b raise ArgumentError, "public key must be #{BYTES} bytes (got #{key.bytesize})" unless key.bytesize == BYTES @key = key end |
Instance Method Details
#==(other) ⇒ Boolean
Constant-time equality comparison.
29 30 31 |
# File 'lib/nuckle/public_key.rb', line 29 def ==(other) other.is_a?(PublicKey) && Util.verify32(@key, other.to_s) end |
#to_bytes ⇒ String
Returns raw 32-byte key (binary).
21 22 |
# File 'lib/nuckle/public_key.rb', line 21 def to_bytes = @key # @return [String] raw 32-byte key (binary) |
#to_s ⇒ String
Returns raw 32-byte key (binary).
23 |
# File 'lib/nuckle/public_key.rb', line 23 def to_s = @key |