pub trait HasherExt {
// Required methods
fn new_from_context_key(context_key: &ContextKey) -> Self;
fn set_input_offset(&mut self, offset: u64) -> &mut Self;
fn finalize_non_root(&self) -> ChainingValue;
}
Expand description
Extension methods for Hasher
. This is the main entrypoint to the hazmat
module.
Required Methods§
Sourcefn new_from_context_key(context_key: &ContextKey) -> Self
fn new_from_context_key(context_key: &ContextKey) -> Self
Similar to Hasher::new_derive_key
but using a pre-hashed ContextKey
from
hash_derive_key_context
.
The hash_derive_key_context
function is only valid source of the ContextKey
§Example
use blake3::Hasher;
use blake3::hazmat::HasherExt;
let context_key = blake3::hazmat::hash_derive_key_context("foo");
let mut hasher = Hasher::new_from_context_key(&context_key);
hasher.update(b"bar");
let derived_key = *hasher.finalize().as_bytes();
assert_eq!(derived_key, blake3::derive_key("foo", b"bar"));
Sourcefn set_input_offset(&mut self, offset: u64) -> &mut Self
fn set_input_offset(&mut self, offset: u64) -> &mut Self
Configure the Hasher
to process a chunk or subtree starting at offset
bytes into the
whole input.
You must call this function before processing any input with update
or
similar. This step isn’t required for the first chunk, or for a subtree that includes the
first chunk (i.e. when the offset
is zero), but it’s required for all other chunks and
subtrees.
The starting input offset of a subtree implies a maximum possible length for that subtree.
See max_subtree_len
and section 2.1 of the BLAKE3
paper. Note that only
subtrees along the right edge of the whole tree can have a length less than their maximum
possible length.
See the module level examples.
§Panics
This function panics if the Hasher
has already accepted any input with
update
or similar.
This should always be paired with finalize_non_root
. It’s
never correct to use a non-zero input offset with finalize
or
finalize_xof
. The offset
must also be a multiple of
CHUNK_LEN
. Violating either of these rules will currently fail an assertion and panic,
but this is not guaranteed.
Sourcefn finalize_non_root(&self) -> ChainingValue
fn finalize_non_root(&self) -> ChainingValue
Finalize the non-root hash (“chaining value”) of the current chunk or subtree.
Afterwards you can merge subtree chaining values into parent nodes using
merge_subtrees_non_root
and ultimately into the root node with either
merge_subtrees_root
(similar to Hasher::finalize
) or merge_subtrees_root_xof
(similar to Hasher::finalize_xof
).
See the module level examples, particularly the discussion of valid tree structures.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.