Class: PQCrypto::KEM::PublicKey
- Inherits:
-
Object
- Object
- PQCrypto::KEM::PublicKey
- Defined in:
- lib/pq_crypto/kem.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #encapsulate ⇒ Object
- #encapsulate_to_bytes ⇒ Object
- #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
Constructor Details
#initialize(algorithm, bytes) ⇒ PublicKey
Returns a new instance of PublicKey.
159 160 161 162 163 |
# File 'lib/pq_crypto/kem.rb', line 159 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.
157 158 159 |
# File 'lib/pq_crypto/kem.rb', line 157 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
197 198 199 200 |
# File 'lib/pq_crypto/kem.rb', line 197 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.send(:bytes_for_native), @bytes) end |
#encapsulate ⇒ Object
185 186 187 188 189 190 |
# File 'lib/pq_crypto/kem.rb', line 185 def encapsulate ciphertext, shared_secret = PQCrypto.__send__(KEM.send(:native_method_for, @algorithm, :encapsulate), @bytes) EncapsulationResult.new(ciphertext, shared_secret) rescue ArgumentError => e raise InvalidKeyError, e. end |
#encapsulate_to_bytes ⇒ Object
192 193 194 195 |
# File 'lib/pq_crypto/kem.rb', line 192 def encapsulate_to_bytes result = encapsulate [result.ciphertext, result.shared_secret] end |
#fingerprint ⇒ Object
208 209 210 |
# File 'lib/pq_crypto/kem.rb', line 208 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
204 205 206 |
# File 'lib/pq_crypto/kem.rb', line 204 def hash fingerprint.hash end |
#to_bytes ⇒ Object
165 166 167 |
# File 'lib/pq_crypto/kem.rb', line 165 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
169 170 171 |
# File 'lib/pq_crypto/kem.rb', line 169 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
173 174 175 |
# File 'lib/pq_crypto/kem.rb', line 173 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#to_spki_der ⇒ Object
177 178 179 |
# File 'lib/pq_crypto/kem.rb', line 177 def to_spki_der SPKI.encode_der(@algorithm, @bytes) end |
#to_spki_pem ⇒ Object
181 182 183 |
# File 'lib/pq_crypto/kem.rb', line 181 def to_spki_pem SPKI.encode_pem(@algorithm, @bytes) end |