Class: Botan::MAC
- Inherits:
-
Object
- Object
- Botan::MAC
- Defined in:
- lib/botan/mac.rb
Overview
Message Authentication Code
Examples
examples/mac.rb
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
Instance Method Summary collapse
- #digest ⇒ Object
- #hexdigest ⇒ Object
-
#initialize(algo) ⇒ MAC
constructor
A new instance of MAC.
- #inspect ⇒ Object
-
#key=(key) ⇒ Object
Sets the key for the MAC.
-
#output_length ⇒ Integer
Retrieve the output length of the MAC.
-
#reset ⇒ self
Resets the instace back to a clean state, as if no key and input have been supplied.
-
#update(data) ⇒ self
(also: #<<)
Adds input to the MAC computation.
Constructor Details
#initialize(algo) ⇒ MAC
Returns a new instance of MAC.
19 20 21 22 23 24 25 26 |
# File 'lib/botan/mac.rb', line 19 def initialize(algo) flags = 0 ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_mac_init, ptr, algo, flags) ptr = ptr.read_pointer raise Botan::Error, 'botan_mac_init 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.
29 30 31 |
# File 'lib/botan/mac.rb', line 29 def self.destroy(ptr) LibBotan.botan_mac_destroy(ptr) end |
Instance Method Details
#digest ⇒ Object
68 69 70 71 72 |
# File 'lib/botan/mac.rb', line 68 def digest out_buf = FFI::MemoryPointer.new(:uint8, output_length) Botan.call_ffi(:botan_mac_final, @ptr, out_buf) out_buf.read_bytes(out_buf.size) end |
#hexdigest ⇒ Object
74 75 76 |
# File 'lib/botan/mac.rb', line 74 def hexdigest Botan.hex_encode(digest) end |
#inspect ⇒ Object
78 79 80 |
# File 'lib/botan/mac.rb', line 78 def inspect Botan.inspect_ptr(self) end |
#key=(key) ⇒ Object
Sets the key for the MAC. This must be called before #update.
55 56 57 |
# File 'lib/botan/mac.rb', line 55 def key=(key) Botan.call_ffi(:botan_mac_set_key, @ptr, key, key.bytesize) end |
#output_length ⇒ Integer
Retrieve the output length of the MAC.
45 46 47 48 49 |
# File 'lib/botan/mac.rb', line 45 def output_length length_ptr = FFI::MemoryPointer.new(:size_t) Botan.call_ffi(:botan_mac_output_length, @ptr, length_ptr) length_ptr.read(:size_t) end |