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.



154
155
156
157
158
# File 'lib/pq_crypto/signature.rb', line 154

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

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



152
153
154
# File 'lib/pq_crypto/signature.rb', line 152

def algorithm
  @algorithm
end

Instance Method Details

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



183
184
185
186
# File 'lib/pq_crypto/signature.rb', line 183

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

#hashObject



190
191
192
# File 'lib/pq_crypto/signature.rb', line 190

def hash
  object_id.hash
end

#inspectObject



194
195
196
# File 'lib/pq_crypto/signature.rb', line 194

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

#sign(message) ⇒ Object



172
173
174
175
176
# File 'lib/pq_crypto/signature.rb', line 172

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

#to_bytesObject



160
161
162
# File 'lib/pq_crypto/signature.rb', line 160

def to_bytes
  @bytes.dup
end

#to_pqc_container_derObject



164
165
166
# File 'lib/pq_crypto/signature.rb', line 164

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

#to_pqc_container_pemObject



168
169
170
# File 'lib/pq_crypto/signature.rb', line 168

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

#wipe!Object



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

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