Class: PQCrypto::KEM::SecretKey
- Inherits:
-
Object
- Object
- PQCrypto::KEM::SecretKey
- 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?)
- #decapsulate(ciphertext) ⇒ Object
- #fingerprint ⇒ Object
- #hash ⇒ Object
-
#initialize(algorithm, bytes) ⇒ SecretKey
constructor
A new instance of SecretKey.
- #to_bytes ⇒ Object
- #to_pqc_container_der ⇒ Object
- #to_pqc_container_pem ⇒ Object
- #wipe! ⇒ Object
Constructor Details
#initialize(algorithm, bytes) ⇒ SecretKey
Returns a new instance of SecretKey.
150 151 152 153 154 |
# File 'lib/pq_crypto/kem.rb', line 150 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.
148 149 150 |
# File 'lib/pq_crypto/kem.rb', line 148 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
179 180 181 182 |
# File 'lib/pq_crypto/kem.rb', line 179 def ==(other) return false unless other.is_a?(SecretKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#decapsulate(ciphertext) ⇒ Object
168 169 170 171 172 |
# File 'lib/pq_crypto/kem.rb', line 168 def decapsulate(ciphertext) PQCrypto.__send__(:native_ml_kem_decapsulate, String(ciphertext).b, @bytes) rescue ArgumentError => e raise InvalidCiphertextError, e. end |
#fingerprint ⇒ Object
190 191 192 |
# File 'lib/pq_crypto/kem.rb', line 190 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
186 187 188 |
# File 'lib/pq_crypto/kem.rb', line 186 def hash fingerprint.hash end |
#to_bytes ⇒ Object
156 157 158 |
# File 'lib/pq_crypto/kem.rb', line 156 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
160 161 162 |
# File 'lib/pq_crypto/kem.rb', line 160 def to_pqc_container_der Serialization.secret_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
164 165 166 |
# File 'lib/pq_crypto/kem.rb', line 164 def to_pqc_container_pem Serialization.secret_key_to_pqc_container_pem(@algorithm, @bytes) end |
#wipe! ⇒ Object
174 175 176 177 |
# File 'lib/pq_crypto/kem.rb', line 174 def wipe! PQCrypto.secure_wipe(@bytes) self end |