Class: Botan::PK::KeyAgreement

Inherits:
Object
  • Object
show all
Defined in:
lib/botan/pk/op/keyagreement.rb

Overview

Public Key Key Agreement Operation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, kdf: Botan::DEFAULT_KDF_ALGO) ⇒ KeyAgreement

Returns a new instance of KeyAgreement.

Parameters:

  • key (Botan::PK::PrivateKey)

    the private key

  • kdf (String) (defaults to: Botan::DEFAULT_KDF_ALGO)

    the KDF algorithm name



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_valueObject (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

#inspectObject



53
54
55
# File 'lib/botan/pk/op/keyagreement.rb', line 53

def inspect
  Botan.inspect_ptr(self)
end