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
- #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.
143 144 145 146 147 |
# File 'lib/pq_crypto/kem.rb', line 143 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.
141 142 143 |
# File 'lib/pq_crypto/kem.rb', line 141 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
172 173 174 |
# File 'lib/pq_crypto/kem.rb', line 172 def ==(other) other.is_a?(SecretKey) && other.algorithm == algorithm && other.to_bytes == @bytes end |
#decapsulate(ciphertext) ⇒ Object
161 162 163 164 165 |
# File 'lib/pq_crypto/kem.rb', line 161 def decapsulate(ciphertext) PQCrypto.__send__(:native_ml_kem_decapsulate, String(ciphertext).b, @bytes) rescue ArgumentError => e raise InvalidCiphertextError, e. end |
#hash ⇒ Object
178 179 180 |
# File 'lib/pq_crypto/kem.rb', line 178 def hash [self.class, algorithm, @bytes].hash end |
#to_bytes ⇒ Object
149 150 151 |
# File 'lib/pq_crypto/kem.rb', line 149 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
153 154 155 |
# File 'lib/pq_crypto/kem.rb', line 153 def to_pqc_container_der Serialization.secret_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
157 158 159 |
# File 'lib/pq_crypto/kem.rb', line 157 def to_pqc_container_pem Serialization.secret_key_to_pqc_container_pem(@algorithm, @bytes) end |
#wipe! ⇒ Object
167 168 169 170 |
# File 'lib/pq_crypto/kem.rb', line 167 def wipe! PQCrypto.secure_wipe(@bytes) self end |