Class: Botan::PK::Verify
- Inherits:
-
Object
- Object
- Botan::PK::Verify
- Defined in:
- lib/botan/pk/op/verify.rb
Overview
Public Key Verify Operation
See PublicKey#verify for a simpler interface.
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
Instance Method Summary collapse
-
#check_signature(signature) ⇒ Boolean
Checks the signature against the previously-provided data.
-
#initialize(key:, padding: nil) ⇒ Verify
constructor
A new instance of Verify.
- #inspect ⇒ Object
-
#update(msg) ⇒ self
(also: #<<)
Adds more data to the message currently being verified.
Constructor Details
#initialize(key:, padding: nil) ⇒ Verify
Returns a new instance of Verify.
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.
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 |
#inspect ⇒ Object
70 71 72 |
# File 'lib/botan/pk/op/verify.rb', line 70 def inspect Botan.inspect_ptr(self) end |