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.
265 266 267 268 269 |
# File 'lib/pq_crypto/signature.rb', line 265 def initialize(algorithm, bytes) @algorithm = algorithm @bytes = Internal.binary_string(bytes) validate_length! end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
263 264 265 |
# File 'lib/pq_crypto/signature.rb', line 263 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
316 317 318 319 |
# File 'lib/pq_crypto/signature.rb', line 316 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
327 328 329 |
# File 'lib/pq_crypto/signature.rb', line 327 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
323 324 325 |
# File 'lib/pq_crypto/signature.rb', line 323 def hash fingerprint.hash end |
#to_bytes ⇒ Object
271 272 273 |
# File 'lib/pq_crypto/signature.rb', line 271 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
275 276 277 |
# File 'lib/pq_crypto/signature.rb', line 275 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
279 280 281 |
# File 'lib/pq_crypto/signature.rb', line 279 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#to_spki_der ⇒ Object
283 284 285 |
# File 'lib/pq_crypto/signature.rb', line 283 def to_spki_der SPKI.encode_der(@algorithm, @bytes) end |
#to_spki_pem ⇒ Object
287 288 289 |
# File 'lib/pq_crypto/signature.rb', line 287 def to_spki_pem SPKI.encode_pem(@algorithm, @bytes) end |
#verify(message, signature, context: "".b) ⇒ Object
291 292 293 294 295 296 297 298 |
# File 'lib/pq_crypto/signature.rb', line 291 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
300 301 302 303 |
# File 'lib/pq_crypto/signature.rb', line 300 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
305 306 307 |
# File 'lib/pq_crypto/signature.rb', line 305 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
309 310 311 312 313 314 |
# File 'lib/pq_crypto/signature.rb', line 309 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 |