class Botan::Digest
Class for calculating message digests using Botan's hash functions.
This should behave nearly identically to {::Digest} and {OpenSSL::Digest}. Some differences are:
-
Algorithm names. Example: OpenSSL expects `RIPEMD160`,
Botan
uses `RIPEMD-160`. -
OIDs. Not currently supported.
Examples¶ ↑
examples/digest.rb¶ ↑
{include:file:examples/digest.rb}
Attributes
name[R]
ptr[R]
@api private
Public Class Methods
destroy(ptr)
click to toggle source
@api private
# File lib/botan/digest.rb, line 49 def self.destroy(ptr) LibBotan.botan_hash_destroy(ptr) end
digest(name, data)
click to toggle source
Calls superclass method
# File lib/botan/digest.rb, line 53 def self.digest(name, data) super(data, name) end
new(algo)
click to toggle source
# File lib/botan/digest.rb, line 30 def initialize(algo) @name = algo flags = 0 ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_hash_init, ptr, algo, flags) ptr = ptr.read_pointer raise Botan::Error, 'botan_hash_init returned NULL' if ptr.null? @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) end
Public Instance Methods
block_length()
click to toggle source
Retrieve the block length for the hash.
@return [Integer]
# File lib/botan/digest.rb, line 91 def block_length length_ptr = FFI::MemoryPointer.new(:size_t) Botan.call_ffi(:botan_hash_block_size, @ptr, length_ptr) length_ptr.read(:size_t) end
digest_length()
click to toggle source
Retrieve the length of the digest.
@return [Integer]
# File lib/botan/digest.rb, line 100 def digest_length length_ptr = FFI::MemoryPointer.new(:size_t) Botan.call_ffi(:botan_hash_output_length, @ptr, length_ptr) length_ptr.read(:size_t) end
initialize_copy(source)
click to toggle source
# File lib/botan/digest.rb, line 40 def initialize_copy(source) @name = source.name ptr = FFI::MemoryPointer.new(:pointer) Botan.call_ffi(:botan_hash_copy_state, ptr, source.ptr) ptr = ptr.read_pointer @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) end
reset()
click to toggle source
Resets the instace back to a clean state, as if no data has been supplied.
@return [self]
# File lib/botan/digest.rb, line 119 def reset Botan.call_ffi(:botan_hash_clear, @ptr) self end
update(data)
click to toggle source
Adds input to the digest computation.
@param [String] data @return [self]
# File lib/botan/digest.rb, line 110 def update(data) Botan.call_ffi(:botan_hash_update, @ptr, data, data.bytesize) self end
Also aliased as: <<
Private Instance Methods
finish()
click to toggle source
# File lib/botan/digest.rb, line 128 def finish out_buf = FFI::MemoryPointer.new(:uint8, digest_length) Botan.call_ffi(:botan_hash_final, @ptr, out_buf) out_buf.read_bytes(out_buf.size) end