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
- #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.
92 93 94 95 96 |
# File 'lib/pq_crypto/kem.rb', line 92 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.
90 91 92 |
# File 'lib/pq_crypto/kem.rb', line 90 def algorithm @algorithm end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
122 123 124 |
# File 'lib/pq_crypto/kem.rb', line 122 def ==(other) other.is_a?(PublicKey) && other.algorithm == algorithm && other.to_bytes == @bytes end |
#encapsulate ⇒ Object
110 111 112 113 114 115 |
# File 'lib/pq_crypto/kem.rb', line 110 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
117 118 119 120 |
# File 'lib/pq_crypto/kem.rb', line 117 def encapsulate_to_bytes result = encapsulate [result.ciphertext, result.shared_secret] end |
#hash ⇒ Object
128 129 130 |
# File 'lib/pq_crypto/kem.rb', line 128 def hash [self.class, algorithm, @bytes].hash end |
#to_bytes ⇒ Object
98 99 100 |
# File 'lib/pq_crypto/kem.rb', line 98 def to_bytes @bytes.dup end |
#to_pqc_container_der ⇒ Object
102 103 104 |
# File 'lib/pq_crypto/kem.rb', line 102 def to_pqc_container_der Serialization.public_key_to_pqc_container_der(@algorithm, @bytes) end |
#to_pqc_container_pem ⇒ Object
106 107 108 |
# File 'lib/pq_crypto/kem.rb', line 106 def to_pqc_container_pem Serialization.public_key_to_pqc_container_pem(@algorithm, @bytes) end |