Class: RbNaCl::Signatures::Ed25519::VerifyKey
- Inherits:
-
Object
- Object
- RbNaCl::Signatures::Ed25519::VerifyKey
- Extended by:
- RbNaCl::Sodium
- Includes:
- KeyComparator, RbNaCl::Serializable
- Defined in:
- lib/rbnacl/signatures/ed25519/verify_key.rb
Overview
The public key counterpart to an Ed25519 SigningKey for producing digital signatures. Like the name says, VerifyKeys can be used to verify that a given digital signature is authentic.
For more information on the Ed25519 digital signature system, please see the SigningKey documentation.
Class Method Summary collapse
-
.signature_bytes ⇒ Integer
The size of signatures verified by the VerifyKey class.
Instance Method Summary collapse
-
#initialize(key) ⇒ RbNaCl::VerifyKey
constructor
Create a new VerifyKey object from a public key.
-
#primitive ⇒ Symbol
The crypto primitive this VerifyKey class uses for signatures.
-
#signature_bytes ⇒ Integer
The size of signatures verified by the VerifyKey instance.
-
#to_bytes ⇒ String
Return the raw key in byte format.
-
#verify(signature, message) ⇒ Boolean
Verify a signature for a given message.
Methods included from RbNaCl::Sodium
sodium_constant, sodium_function, sodium_primitive, sodium_type
Methods included from RbNaCl::Serializable
Methods included from KeyComparator
Constructor Details
#initialize(key) ⇒ RbNaCl::VerifyKey
Create a new VerifyKey object from a public key.
29 30 31 32 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 29 def initialize(key) @key = key.to_str Util.check_length(@key, Ed25519::VERIFYKEYBYTES, "key") end |
Class Method Details
.signature_bytes ⇒ Integer
The size of signatures verified by the VerifyKey class
69 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 69 def self.signature_bytes; Ed25519::SIGNATUREBYTES; end |
Instance Method Details
#primitive ⇒ Symbol
The crypto primitive this VerifyKey class uses for signatures
64 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 64 def primitive; self.class.primitive; end |
#signature_bytes ⇒ Integer
The size of signatures verified by the VerifyKey instance
74 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 74 def signature_bytes; Ed25519::SIGNATUREBYTES; end |
#to_bytes ⇒ String
Return the raw key in byte format
59 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 59 def to_bytes; @key; end |
#verify(signature, message) ⇒ Boolean
Verify a signature for a given message
Raises if the signature is invalid.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbnacl/signatures/ed25519/verify_key.rb', line 45 def verify(signature, ) signature = signature.to_str Util.check_length(signature, signature_bytes, "signature") sig_and_msg = signature + buffer = Util.zeros(sig_and_msg.bytesize) buffer_len = Util.zeros(FFI::Type::LONG_LONG.size) self.class.sign_ed25519_open(buffer, buffer_len, sig_and_msg, sig_and_msg.bytesize, @key) || raise(BadSignatureError, "signature was forged/corrupt") end |