Struct kangarootwelve_xkcp::Hasher
source · [−]pub struct Hasher(_);
Expand description
An incremental hash state that can accept any number of writes.
Examples
// Hash an input incrementally.
let mut hasher = kangarootwelve_xkcp::Hasher::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
assert_eq!(hasher.finalize(), kangarootwelve_xkcp::hash(b"foobarbaz"));
// Extended output. OutputReader also implements Read and Seek.
let mut hasher = kangarootwelve_xkcp::Hasher::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], kangarootwelve_xkcp::hash(b"foobarbaz").as_bytes());
Implementations
sourceimpl Hasher
impl Hasher
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(&mut self) -> Hash
pub fn finalize(&mut self) -> Hash
Finalize the hash state and return the Hash
of
the input. This method is equivalent to
finalize_custom
with an empty
customization string.
You can only finalize a Hasher
once. Additional calls to any of the
finalize methods will panic.
sourcepub fn finalize_custom(&mut self, customization: &[u8]) -> Hash
pub fn finalize_custom(&mut self, customization: &[u8]) -> Hash
Finalize the hash state using the given customization string and return
the Hash
of the input.
You can only finalize a Hasher
once. Additional calls to any of the
finalize methods will panic.
sourcepub fn finalize_xof(&mut self) -> OutputReaderⓘNotable traits for OutputReaderimpl Read for OutputReader
pub fn finalize_xof(&mut self) -> OutputReaderⓘNotable traits for OutputReaderimpl Read for OutputReader
Finalize the hash state and return an OutputReader
, which can
supply any number of output bytes. This method is equivalent to
finalize_custom_xof
with an empty
customization string.
You can only finalize a Hasher
once. Additional calls to any of the
finalize methods will panic.
sourcepub fn finalize_custom_xof(&mut self, customization: &[u8]) -> OutputReaderⓘNotable traits for OutputReaderimpl Read for OutputReader
pub fn finalize_custom_xof(&mut self, customization: &[u8]) -> OutputReaderⓘNotable traits for OutputReaderimpl Read for OutputReader
Finalize the hash state and return an OutputReader
, which can
supply any number of output bytes.
You can only finalize a Hasher
once. Additional calls to any of the
finalize methods will panic.