Class: PQCrypto::KEM::PublicKey
- Inherits:
-
Object
- Object
- PQCrypto::KEM::PublicKey
- Defined in:
- lib/pq_crypto/kem.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #encapsulate ⇒ Object
- #encapsulate_to_bytes ⇒ Object
- #fingerprint ⇒ Object
- #hash ⇒ Object
-
#initialize(algorithm, bytes) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #to_bytes ⇒ Object
- #to_pqc_container_der ⇒ Object
- #to_pqc_container_pem ⇒ Object
Constructor Details
#initialize(algorithm, bytes) ⇒ PublicKey
Returns a new instance of PublicKey.
94 95 96 97 98 |
# File 'lib/pq_crypto/kem.rb', line 94 def initialize(algorithm, bytes) @algorithm = algorithm @bytes = String(bytes).b validate_length! end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
92 93 94 |
# File 'lib/pq_crypto/kem.rb', line 92 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
124 125 126 127 |
# File 'lib/pq_crypto/kem.rb', line 124 def ==(other) return false unless other.is_a?(PublicKey) && other.algorithm == algorithm PQCrypto.__send__(:native_ct_equals, other.to_bytes, @bytes) end |
#encapsulate ⇒ Object
112 113 114 115 116 117 |
# File 'lib/pq_crypto/kem.rb', line 112 def encapsulate ciphertext, shared_secret = PQCrypto.__send__(:native_ml_kem_encapsulate, @bytes) EncapsulationResult.new(ciphertext, shared_secret) rescue ArgumentError => e raise InvalidKeyError, e. end |
#encapsulate_to_bytes ⇒ Object
119 120 121 122 |
# File 'lib/pq_crypto/kem.rb', line 119 def encapsulate_to_bytes result = encapsulate [result.ciphertext, result.shared_secret] end |
#fingerprint ⇒ Object
135 136 137 |
# File 'lib/pq_crypto/kem.rb', line 135 def fingerprint Digest::SHA256.digest(@bytes) end |
#hash ⇒ Object
131 132 133 |
# File 'lib/pq_crypto/kem.rb', line 131 def hash fingerprint.hash end |
#to_bytes ⇒ Object
100 101 102 |
# File 'lib/pq_crypto/kem.rb', line 100 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
104 105 106 |
# File 'lib/pq_crypto/kem.rb', line 104 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
108 109 110 |
# File 'lib/pq_crypto/kem.rb', line 108 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |