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, context: "".b) ⇒ Object
- #verify!(message, signature, context: "".b) ⇒ 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.
279 280 281 282 283 |
# File 'lib/pq_crypto/signature.rb', line 279 def initialize(algorithm, bytes) @algorithm = algorithm @bytes = Internal.frozen_binary_string(bytes) validate_length! end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
277 278 279 |
# File 'lib/pq_crypto/signature.rb', line 277 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
330 331 332 333 |
# File 'lib/pq_crypto/signature.rb', line 330 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm Internal.constant_time_equal?(other.send(:bytes_for_native), @bytes) end |
#fingerprint ⇒ Object
341 342 343 |
# File 'lib/pq_crypto/signature.rb', line 341 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
337 338 339 |
# File 'lib/pq_crypto/signature.rb', line 337 def hash fingerprint.hash end |
#to_bytes ⇒ Object
285 286 287 |
# File 'lib/pq_crypto/signature.rb', line 285 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
289 290 291 |
# File 'lib/pq_crypto/signature.rb', line 289 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
293 294 295 |
# File 'lib/pq_crypto/signature.rb', line 293 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#to_spki_der ⇒ Object
297 298 299 |
# File 'lib/pq_crypto/signature.rb', line 297 def to_spki_der SPKI.encode_der(@algorithm, @bytes) end |
#to_spki_pem ⇒ Object
301 302 303 |
# File 'lib/pq_crypto/signature.rb', line 301 def to_spki_pem SPKI.encode_pem(@algorithm, @bytes) end |
#verify(message, signature, context: "".b) ⇒ Object
305 306 307 308 309 310 311 312 |
# File 'lib/pq_crypto/signature.rb', line 305 def verify(, signature, context: "".b) context = Signature.send(:validate_context!, context) begin PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :verify), Internal.binary_string(), Internal.binary_string(signature), @bytes, context) rescue ArgumentError => e raise InvalidKeyError, e. end end |
#verify!(message, signature, context: "".b) ⇒ Object
314 315 316 317 |
# File 'lib/pq_crypto/signature.rb', line 314 def verify!(, signature, context: "".b) raise PQCrypto::VerificationError, "Verification failed" unless verify(, signature, context: context) true end |
#verify_io(io, signature, chunk_size: 1 << 20, context: "".b) ⇒ Object
319 320 321 |
# File 'lib/pq_crypto/signature.rb', line 319 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
323 324 325 326 327 328 |
# File 'lib/pq_crypto/signature.rb', line 323 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 |