pub struct Hasher<N>(/* private fields */);
Expand description
An incremental hash state that can accept any number of writes
The N
parameter indicates the security strength level in number of bits.
Valid values for it are:
Any other value will fail to compile
§Examples
// hash an input incrementally
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
assert_eq!(hasher.finalize(), marsupial::hash::<KT128>(b"foobarbaz"));
// extended output. `OutputReader` also implements `Read` and `Seek`
let mut hasher = Hasher::<KT128>::new();
hasher.update(b"foobarbaz");
let mut output = [0; 1000];
let mut output_reader = hasher.finalize_xof();
output_reader.squeeze(&mut output);
assert_eq!(&output[..32], marsupial::hash::<KT128>(b"foobarbaz").as_bytes());
Implementations§
Source§impl<N> Hasher<N>where
N: SecurityLevel,
impl<N> Hasher<N>where
N: SecurityLevel,
Sourcepub fn update(&mut self, input: &[u8])
pub fn update(&mut self, input: &[u8])
Add input bytes to the hash state. You can call this any number of
times, until the Hasher
is finalized
Sourcepub fn finalize(self) -> N::Hash
pub fn finalize(self) -> N::Hash
Finalize the hash state, consuming the Hasher
, and return the
Hash
of the input. This method is equivalent to
finalize_custom
with an empty
customization string
Sourcepub fn finalize_custom(self, customization: &[u8]) -> N::Hash
pub fn finalize_custom(self, customization: &[u8]) -> N::Hash
Sourcepub fn finalize_xof(self) -> OutputReader ⓘ
pub fn finalize_xof(self) -> OutputReader ⓘ
Finalize the hash state, consuming the Hasher
and returning
an OutputReader
, which can supply any number of output bytes.
This method is equivalent to
finalize_custom_xof
with an empty
customization string
Sourcepub fn finalize_custom_xof(self, customization: &[u8]) -> OutputReader ⓘ
pub fn finalize_custom_xof(self, customization: &[u8]) -> OutputReader ⓘ
Finalize the hash state, consuming the Hasher
and returning an
OutputReader
, which can supply any number of output bytes