Class: PQCrypto::KEM::SecretKey

Inherits:
Object
  • Object
show all
Defined in:
lib/pq_crypto/kem.rb

Direct Known Subclasses

HybridKEM::SecretKey

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#algorithmObject (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.message
end

#hashObject



178
179
180
# File 'lib/pq_crypto/kem.rb', line 178

def hash
  [self.class, algorithm, @bytes].hash
end

#to_bytesObject



149
150
151
# File 'lib/pq_crypto/kem.rb', line 149

def to_bytes
  @bytes.dup
end

#to_pqc_container_derObject



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_pemObject



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