Class: Botan::Digest
- Inherits:
-
Digest::Class
- Object
- Digest::Class
- Botan::Digest
- Defined in:
- lib/botan/digest.rb
Overview
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
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #ptr ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#block_length ⇒ Integer
Retrieve the block length for the hash.
-
#digest_length ⇒ Integer
Retrieve the length of the digest.
-
#initialize(algo) ⇒ Digest
constructor
A new instance of Digest.
- #initialize_copy(source) ⇒ Object
-
#reset ⇒ self
Resets the instace back to a clean state, as if no data has been supplied.
-
#update(data) ⇒ self
(also: #<<)
Adds input to the digest computation.
Constructor Details
#initialize(algo) ⇒ Digest
Returns a new instance of Digest.
30 31 32 33 34 35 36 37 38 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/botan/digest.rb', line 26 def name @name end |
#ptr ⇒ Object (readonly)
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.
28 29 30 |
# File 'lib/botan/digest.rb', line 28 def ptr @ptr 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.
49 50 51 |
# File 'lib/botan/digest.rb', line 49 def self.destroy(ptr) LibBotan.botan_hash_destroy(ptr) end |
.digest(name, data) ⇒ Object
53 54 55 |
# File 'lib/botan/digest.rb', line 53 def self.digest(name, data) super(data, name) end |
Instance Method Details
#block_length ⇒ Integer
Retrieve the block length for the hash.
91 92 93 94 95 |
# 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 ⇒ Integer
Retrieve the length of the digest.
100 101 102 103 104 |
# 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) ⇒ Object
40 41 42 43 44 45 46 |
# 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 ⇒ self
Resets the instace back to a clean state, as if no data has been supplied.
119 120 121 122 |
# File 'lib/botan/digest.rb', line 119 def reset Botan.call_ffi(:botan_hash_clear, @ptr) self end |
#update(data) ⇒ self Also known as: <<
Adds input to the digest computation.
110 111 112 113 |
# File 'lib/botan/digest.rb', line 110 def update(data) Botan.call_ffi(:botan_hash_update, @ptr, data, data.bytesize) self end |