Class: Botan::PK::KeyAgreement
- Inherits:
-
Object
- Object
- Botan::PK::KeyAgreement
- Defined in:
- lib/botan/pk/op/keyagreement.rb
Overview
Public Key Key Agreement Operation
Instance Attribute Summary collapse
-
#public_value ⇒ Object
readonly
Returns the value of attribute public_value.
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
Instance Method Summary collapse
- #agree(other_key:, key_length:, salt:) ⇒ Object
-
#initialize(key:, kdf: Botan::DEFAULT_KDF_ALGO) ⇒ KeyAgreement
constructor
A new instance of KeyAgreement.
- #inspect ⇒ Object
Constructor Details
#initialize(key:, kdf: Botan::DEFAULT_KDF_ALGO) ⇒ KeyAgreement
Returns a new instance of KeyAgreement.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/botan/pk/op/keyagreement.rb', line 20 def initialize(key:, kdf: Botan::DEFAULT_KDF_ALGO) unless key.instance_of?(PrivateKey) raise Botan::Error, 'KeyAgreement requires an instance of PrivateKey' end ptr = FFI::MemoryPointer.new(:pointer) flags = 0 Botan.call_ffi(:botan_pk_op_key_agreement_create, ptr, key.ptr, kdf, flags) ptr = ptr.read_pointer if ptr.null? raise Botan::Error, 'botan_pk_op_key_agreement_create returned NULL' end @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) @public_value = Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_pk_op_key_agreement_export_public(key.ptr, b, bl) }) end |
Instance Attribute Details
#public_value ⇒ Object (readonly)
Returns the value of attribute public_value.
17 18 19 |
# File 'lib/botan/pk/op/keyagreement.rb', line 17 def public_value @public_value end |
Class Method Details
.destroy(ptr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/botan/pk/op/keyagreement.rb', line 39 def self.destroy(ptr) LibBotan.botan_pk_op_key_agreement_destroy(ptr) end |
Instance Method Details
#agree(other_key:, key_length:, salt:) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/botan/pk/op/keyagreement.rb', line 43 def agree(other_key:, key_length:, salt:) other_buf = FFI::MemoryPointer.from_data(other_key) salt_buf = FFI::MemoryPointer.from_data(salt) Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_pk_op_key_agreement(@ptr, b, bl, other_buf, other_buf.size, salt_buf, salt_buf.size) }, guess: key_length) end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/botan/pk/op/keyagreement.rb', line 53 def inspect Botan.inspect_ptr(self) end |