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.



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

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

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



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

def algorithm
  @algorithm
end

Instance Method Details

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



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

def ==(other)
  other.is_a?(SecretKey) && other.algorithm == algorithm && other.to_bytes == @bytes
end

#hashObject



186
187
188
# File 'lib/pq_crypto/signature.rb', line 186

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

#sign(message) ⇒ Object



169
170
171
172
173
# File 'lib/pq_crypto/signature.rb', line 169

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

#to_bytesObject



157
158
159
# File 'lib/pq_crypto/signature.rb', line 157

def to_bytes
  @bytes.dup
end

#to_pqc_container_derObject



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

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

#to_pqc_container_pemObject



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

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

#wipe!Object



175
176
177
178
# File 'lib/pq_crypto/signature.rb', line 175

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