Class: PQCrypto::Signature::PublicKey
- Inherits:
-
Object
- Object
- PQCrypto::Signature::PublicKey
- Defined in:
- lib/pq_crypto/signature.rb
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(algorithm, bytes) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #to_bytes ⇒ Object
- #to_pqc_container_der ⇒ Object
- #to_pqc_container_pem ⇒ Object
- #verify(message, signature) ⇒ Object
- #verify!(message, signature) ⇒ Object
Constructor Details
#initialize(algorithm, bytes) ⇒ PublicKey
Returns a new instance of PublicKey.
97 98 99 100 101 |
# File 'lib/pq_crypto/signature.rb', line 97 def initialize(algorithm, bytes) @algorithm = algorithm @bytes = String(bytes).b validate_length! end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
95 96 97 |
# File 'lib/pq_crypto/signature.rb', line 95 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
130 131 132 |
# File 'lib/pq_crypto/signature.rb', line 130 def ==(other) other.is_a?(PublicKey) && other.algorithm == algorithm && other.to_bytes == @bytes end |
#hash ⇒ Object
136 137 138 |
# File 'lib/pq_crypto/signature.rb', line 136 def hash [self.class, algorithm, @bytes].hash end |
#to_bytes ⇒ Object
103 104 105 |
# File 'lib/pq_crypto/signature.rb', line 103 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
107 108 109 |
# File 'lib/pq_crypto/signature.rb', line 107 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
111 112 113 |
# File 'lib/pq_crypto/signature.rb', line 111 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#verify(message, signature) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/pq_crypto/signature.rb', line 115 def verify(, signature) PQCrypto.__send__(:native_verify, String().b, String(signature).b, @bytes) rescue PQCrypto::VerificationError false rescue ArgumentError => e raise InvalidKeyError, e. end |
#verify!(message, signature) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/pq_crypto/signature.rb', line 123 def verify!(, signature) ok = verify(, signature) raise PQCrypto::VerificationError, "Verification failed" unless ok true end |