class Botan::PK::Sign

Public Key Sign Operation

See {Botan::PK::PrivateKey#sign} for a simpler interface.

Public Class Methods

destroy(ptr) click to toggle source

@api private

# File lib/botan/pk/op/sign.rb, line 36
def self.destroy(ptr)
  LibBotan.botan_pk_op_sign_destroy(ptr)
end
new(key:, padding: nil) click to toggle source

@param key [Botan::PK::PrivateKey] the private key @param padding [String] the padding method name

# 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

Public Instance Methods

<<(msg)
Alias for: update
finish(rng = Botan::RNG.new) click to toggle source

Finalizes the signature operation.

@param rng [Botan::PK::RNG] the RNG to use @return [String] the signature

# 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
inspect() click to toggle source
# File lib/botan/pk/op/sign.rb, line 60
def inspect
  Botan.inspect_ptr(self)
end
update(msg) click to toggle source

Adds data to the message currently being signed.

@param msg [String] the data to add @return [self]

# 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
Also aliased as: <<