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
- #to_spki_der ⇒ Object
- #to_spki_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.
252 253 254 255 256 |
# File 'lib/pq_crypto/signature.rb', line 252 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.
250 251 252 |
# File 'lib/pq_crypto/signature.rb', line 250 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
300 301 302 303 |
# File 'lib/pq_crypto/signature.rb', line 300 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#fingerprint ⇒ Object
311 312 313 |
# File 'lib/pq_crypto/signature.rb', line 311 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
307 308 309 |
# File 'lib/pq_crypto/signature.rb', line 307 def hash fingerprint.hash end |
#to_bytes ⇒ Object
258 259 260 |
# File 'lib/pq_crypto/signature.rb', line 258 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
262 263 264 |
# File 'lib/pq_crypto/signature.rb', line 262 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
266 267 268 |
# File 'lib/pq_crypto/signature.rb', line 266 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#to_spki_der ⇒ Object
270 271 272 |
# File 'lib/pq_crypto/signature.rb', line 270 def to_spki_der SPKI.encode_der(@algorithm, @bytes) end |
#to_spki_pem ⇒ Object
274 275 276 |
# File 'lib/pq_crypto/signature.rb', line 274 def to_spki_pem SPKI.encode_pem(@algorithm, @bytes) end |
#verify(message, signature) ⇒ Object
278 279 280 281 282 |
# File 'lib/pq_crypto/signature.rb', line 278 def verify(, signature) PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :verify), String().b, String(signature).b, @bytes) rescue ArgumentError => e raise InvalidKeyError, e. end |
#verify!(message, signature) ⇒ Object
284 285 286 287 |
# File 'lib/pq_crypto/signature.rb', line 284 def verify!(, signature) raise PQCrypto::VerificationError, "Verification failed" unless verify(, signature) true end |
#verify_io(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
289 290 291 |
# File 'lib/pq_crypto/signature.rb', line 289 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
293 294 295 296 297 298 |
# File 'lib/pq_crypto/signature.rb', line 293 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 |