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.
155 156 157 158 159 |
# File 'lib/pq_crypto/kem.rb', line 155 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.
153 154 155 |
# File 'lib/pq_crypto/kem.rb', line 153 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
193 194 195 196 |
# File 'lib/pq_crypto/kem.rb', line 193 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#encapsulate ⇒ Object
181 182 183 184 185 186 |
# File 'lib/pq_crypto/kem.rb', line 181 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
188 189 190 191 |
# File 'lib/pq_crypto/kem.rb', line 188 def encapsulate_to_bytes result = encapsulate [result.ciphertext, result.shared_secret] end |
#fingerprint ⇒ Object
204 205 206 |
# File 'lib/pq_crypto/kem.rb', line 204 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
200 201 202 |
# File 'lib/pq_crypto/kem.rb', line 200 def hash fingerprint.hash end |
#to_bytes ⇒ Object
161 162 163 |
# File 'lib/pq_crypto/kem.rb', line 161 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
165 166 167 |
# File 'lib/pq_crypto/kem.rb', line 165 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
169 170 171 |
# File 'lib/pq_crypto/kem.rb', line 169 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |
#to_spki_der ⇒ Object
173 174 175 |
# File 'lib/pq_crypto/kem.rb', line 173 def to_spki_der SPKI.encode_der(@algorithm, @bytes) end |
#to_spki_pem ⇒ Object
177 178 179 |
# File 'lib/pq_crypto/kem.rb', line 177 def to_spki_pem SPKI.encode_pem(@algorithm, @bytes) end |