class Botan::MAC
Message Authentication Code
Examples¶ ↑
examples/mac.rb¶ ↑
{include:file:examples/mac.rb}
Public Class Methods
destroy(ptr)
click to toggle source
@api private
# File lib/botan/mac.rb, line 29 def self.destroy(ptr) LibBotan.botan_mac_destroy(ptr) end
new(algo)
click to toggle source
@param algo [String] the MAC
algorithm name
# 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
Public Instance Methods
digest()
click to toggle source
# 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()
click to toggle source
# File lib/botan/mac.rb, line 74 def hexdigest Botan.hex_encode(digest) end
inspect()
click to toggle source
# File lib/botan/mac.rb, line 78 def inspect Botan.inspect_ptr(self) end
key=(key)
click to toggle source
Sets the key for the MAC
. This must be called before {#update}.
@param [String] key
# File lib/botan/mac.rb, line 55 def key=(key) Botan.call_ffi(:botan_mac_set_key, @ptr, key, key.bytesize) end
output_length()
click to toggle source
Retrieve the output length of the MAC
.
@return [Integer]
# 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
reset()
click to toggle source
Resets the instace back to a clean state, as if no key and input have been supplied.
@return [self]
# File lib/botan/mac.rb, line 37 def reset Botan.call_ffi(:botan_mac_clear, @ptr) self end