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
Constructor Details
#initialize(algorithm, bytes) ⇒ PublicKey
Returns a new instance of PublicKey.
99 100 101 102 103 |
# File 'lib/pq_crypto/signature.rb', line 99 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.
97 98 99 |
# File 'lib/pq_crypto/signature.rb', line 97 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
128 129 130 131 |
# File 'lib/pq_crypto/signature.rb', line 128 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#fingerprint ⇒ Object
139 140 141 |
# File 'lib/pq_crypto/signature.rb', line 139 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
135 136 137 |
# File 'lib/pq_crypto/signature.rb', line 135 def hash fingerprint.hash end |
#to_bytes ⇒ Object
105 106 107 |
# File 'lib/pq_crypto/signature.rb', line 105 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
109 110 111 |
# File 'lib/pq_crypto/signature.rb', line 109 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
113 114 115 |
# File 'lib/pq_crypto/signature.rb', line 113 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#verify(message, signature) ⇒ Object
117 118 119 120 121 |
# File 'lib/pq_crypto/signature.rb', line 117 def verify(, signature) PQCrypto.__send__(:native_verify, String().b, String(signature).b, @bytes) rescue ArgumentError => e raise InvalidKeyError, e. end |
#verify!(message, signature) ⇒ Object
123 124 125 126 |
# File 'lib/pq_crypto/signature.rb', line 123 def verify!(, signature) raise PQCrypto::VerificationError, "Verification failed" unless verify(, signature) true end |