Class: Botan::PK::Sign

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

Overview

Public Key Sign Operation

See PrivateKey#sign for a simpler interface.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, padding: nil) ⇒ Sign

Returns a new instance of Sign.

Parameters:

  • key (Botan::PK::PrivateKey)

    the private key

  • padding (String) (defaults to: nil)

    the padding method name

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/botan/pk/op/sign.rb', line 22

def initialize(key:, padding: nil)
  padding ||= Botan::DEFAULT_EMSA[key.algo]
  unless key.instance_of?(PrivateKey)
    raise Botan::Error, 'Signing requires an instance of PrivateKey'
  end
  ptr = FFI::MemoryPointer.new(:pointer)
  flags = 0
  Botan.call_ffi(:botan_pk_op_sign_create, ptr, key.ptr, padding, flags)
  ptr = ptr.read_pointer
  raise Botan::Error, 'botan_pk_op_sign_create returned NULL' if ptr.null?
  @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy))
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.



36
37
38
# File 'lib/botan/pk/op/sign.rb', line 36

def self.destroy(ptr)
  LibBotan.botan_pk_op_sign_destroy(ptr)
end

Instance Method Details

#finish(rng = Botan::RNG.new) ⇒ String

Finalizes the signature operation.

Parameters:

  • rng (Botan::PK::RNG) (defaults to: Botan::RNG.new)

    the RNG to use

Returns:

  • (String)

    the signature



54
55
56
57
58
# File 'lib/botan/pk/op/sign.rb', line 54

def finish(rng = Botan::RNG.new)
  Botan.call_ffi_with_buffer(lambda { |b, bl|
    LibBotan.botan_pk_op_sign_finish(@ptr, rng.ptr, b, bl)
  })
end

#inspectObject



60
61
62
# File 'lib/botan/pk/op/sign.rb', line 60

def inspect
  Botan.inspect_ptr(self)
end

#update(msg) ⇒ self Also known as: <<

Adds data to the message currently being signed.

Parameters:

  • msg (String)

    the data to add

Returns:

  • (self)


44
45
46
47
48
# File 'lib/botan/pk/op/sign.rb', line 44

def update(msg)
  msg_buf = FFI::MemoryPointer.from_data(msg)
  Botan.call_ffi(:botan_pk_op_sign_update, @ptr, msg_buf, msg_buf.size)
  self
end