Class: PQCrypto::Signature::PublicKey

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) ⇒ PublicKey

Returns a new instance of PublicKey.



99
100
101
102
103
# File 'lib/pq_crypto/signature.rb', line 99

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

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



97
98
99
# File 'lib/pq_crypto/signature.rb', line 97

def algorithm
  @algorithm
end

Instance Method Details

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



128
129
130
131
# File 'lib/pq_crypto/signature.rb', line 128

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

#fingerprintObject



139
140
141
# File 'lib/pq_crypto/signature.rb', line 139

def fingerprint
  Digest::SHA256.digest(@bytes)
end

#hashObject



135
136
137
# File 'lib/pq_crypto/signature.rb', line 135

def hash
  fingerprint.hash
end

#to_bytesObject



105
106
107
# File 'lib/pq_crypto/signature.rb', line 105

def to_bytes
  @bytes.dup
end

#to_pqc_container_derObject



109
110
111
# File 'lib/pq_crypto/signature.rb', line 109

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

#to_pqc_container_pemObject



113
114
115
# File 'lib/pq_crypto/signature.rb', line 113

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

#verify(message, signature) ⇒ Object



117
118
119
120
121
# File 'lib/pq_crypto/signature.rb', line 117

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

#verify!(message, signature) ⇒ Object



123
124
125
126
# File 'lib/pq_crypto/signature.rb', line 123

def verify!(message, signature)
  raise PQCrypto::VerificationError, "Verification failed" unless verify(message, signature)
  true
end