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?)
- #fingerprint ⇒ Object
- #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
- #verify_io(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
- #verify_io!(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
Constructor Details
#initialize(algorithm, bytes) ⇒ PublicKey
Returns a new instance of PublicKey.
188 189 190 191 192 |
# File 'lib/pq_crypto/signature.rb', line 188 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.
186 187 188 |
# File 'lib/pq_crypto/signature.rb', line 186 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
228 229 230 231 |
# File 'lib/pq_crypto/signature.rb', line 228 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#fingerprint ⇒ Object
239 240 241 |
# File 'lib/pq_crypto/signature.rb', line 239 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
235 236 237 |
# File 'lib/pq_crypto/signature.rb', line 235 def hash fingerprint.hash end |
#to_bytes ⇒ Object
194 195 196 |
# File 'lib/pq_crypto/signature.rb', line 194 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
198 199 200 |
# File 'lib/pq_crypto/signature.rb', line 198 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
202 203 204 |
# File 'lib/pq_crypto/signature.rb', line 202 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#verify(message, signature) ⇒ Object
206 207 208 209 210 |
# File 'lib/pq_crypto/signature.rb', line 206 def verify(, signature) PQCrypto.__send__(:native_verify, String().b, String(signature).b, @bytes) rescue ArgumentError => e raise InvalidKeyError, e. end |
#verify!(message, signature) ⇒ Object
212 213 214 215 |
# File 'lib/pq_crypto/signature.rb', line 212 def verify!(, signature) raise PQCrypto::VerificationError, "Verification failed" unless verify(, signature) true end |
#verify_io(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
217 218 219 |
# File 'lib/pq_crypto/signature.rb', line 217 def verify_io(io, signature, chunk_size: 1 << 20, context: "".b) Signature.send(:_streaming_verify, self, io, signature, chunk_size, context) end |
#verify_io!(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/pq_crypto/signature.rb', line 221 def verify_io!(io, signature, chunk_size: 1 << 20, context: "".b) unless verify_io(io, signature, chunk_size: chunk_size, context: context) raise PQCrypto::VerificationError, "Verification failed" end true end |