Class: PQCrypto::Signature::SecretKey

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm, bytes) ⇒ SecretKey

Returns a new instance of SecretKey.



258
259
260
261
262
# File 'lib/pq_crypto/signature.rb', line 258

def initialize(algorithm, bytes)
  @algorithm = algorithm
  @bytes = String(bytes).b
  validate_length!
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



256
257
258
# File 'lib/pq_crypto/signature.rb', line 256

def algorithm
  @algorithm
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



291
292
293
294
# File 'lib/pq_crypto/signature.rb', line 291

def ==(other)
  return false unless other.is_a?(SecretKey) && other.algorithm == algorithm
  PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes)
end

#hashObject



298
299
300
# File 'lib/pq_crypto/signature.rb', line 298

def hash
  object_id.hash
end

#inspectObject



302
303
304
# File 'lib/pq_crypto/signature.rb', line 302

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} algorithm=#{algorithm.inspect}>"
end

#sign(message) ⇒ Object



276
277
278
279
280
# File 'lib/pq_crypto/signature.rb', line 276

def sign(message)
  PQCrypto.__send__(:native_sign, String(message).b, @bytes)
rescue ArgumentError => e
  raise InvalidKeyError, e.message
end

#sign_io(io, chunk_size: 1 << 20, context: "".b) ⇒ Object



282
283
284
# File 'lib/pq_crypto/signature.rb', line 282

def sign_io(io, chunk_size: 1 << 20, context: "".b)
  Signature.send(:_streaming_sign, self, io, chunk_size, context)
end

#to_bytesObject



264
265
266
# File 'lib/pq_crypto/signature.rb', line 264

def to_bytes
  @bytes.dup
end

#to_pqc_container_derObject



268
269
270
# File 'lib/pq_crypto/signature.rb', line 268

def to_pqc_container_der
  Serialization.secret_key_to_pqc_container_der(@algorithm, @bytes)
end

#to_pqc_container_pemObject



272
273
274
# File 'lib/pq_crypto/signature.rb', line 272

def to_pqc_container_pem
  Serialization.secret_key_to_pqc_container_pem(@algorithm, @bytes)
end

#wipe!Object



286
287
288
289
# File 'lib/pq_crypto/signature.rb', line 286

def wipe!
  PQCrypto.secure_wipe(@bytes)
  self
end