Class: Botan::PK::Verify

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

Overview

Public Key Verify Operation

See PublicKey#verify for a simpler interface.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Verify.

Parameters:

  • key (Botan::PK::PublicKey)

    the public key

  • padding (String) (defaults to: nil)

    the padding method name



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

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



38
39
40
# File 'lib/botan/pk/op/verify.rb', line 38

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

Instance Method Details

#check_signature(signature) ⇒ Boolean

Checks the signature against the previously-provided data.

Parameters:

  • signature (String)

    the signature to check

Returns:

  • (Boolean)

    true if the signature is valid



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/botan/pk/op/verify.rb', line 56

def check_signature(signature)
  sig_buf = FFI::MemoryPointer.from_data(signature)
  # workaround 2.2.0 release bug
  if LibBotan::LIB_VERSION == [2, 2, 0]
    rc = LibBotan.botan_pk_op_verify_finish(@ptr, sig_buf, sig_buf.size)
    raise Botan::Error, 'FFI call unexpectedly failed' \
      unless [0, -1].include?(rc)
  else
    rc = Botan.call_ffi_rc(:botan_pk_op_verify_finish,
                           @ptr, sig_buf, sig_buf.size)
  end
  rc.zero?
end

#inspectObject



70
71
72
# File 'lib/botan/pk/op/verify.rb', line 70

def inspect
  Botan.inspect_ptr(self)
end

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

Adds more data to the message currently being verified.

Parameters:

  • msg (String)

    the data to add

Returns:

  • (self)


46
47
48
49
50
# File 'lib/botan/pk/op/verify.rb', line 46

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