pub fn merge_subtrees_root_xof(
left_child: &ChainingValue,
right_child: &ChainingValue,
mode: Mode<'_>,
) -> OutputReader ⓘ
Expand description
Build a root OutputReader
from two child chaining values.
See also the module level examples, particularly the discussion of valid
tree structures. The left and right child chaining values can come from either
Hasher::finalize_non_root
or merge_subtrees_non_root
.
“Chaining value” is the academic term for a non-root or non-final hash.
Note that inputs of CHUNK_LEN
or less don’t produce any parent nodes and can’t be hashed
using this function. In that case you must get the OutputReader
from
Hasher::finalize_xof
.
§Example
use blake3::hazmat::{merge_subtrees_root_xof, HasherExt, Mode};
use blake3::{Hasher, CHUNK_LEN};
// Hash a 2-chunk subtree in steps. Note that only
// the final chunk can be shorter than CHUNK_LEN.
let chunk0 = &[42; CHUNK_LEN];
let chunk1 = b"hello world";
let chunk0_cv = Hasher::new()
.update(chunk0)
.finalize_non_root();
let chunk1_cv = Hasher::new()
.set_input_offset(CHUNK_LEN as u64)
.update(chunk1)
.finalize_non_root();
// Obtain a blake3::OutputReader at the root and extract 1000 bytes.
let mut output_reader = merge_subtrees_root_xof(&chunk0_cv, &chunk1_cv, Mode::Hash);
let mut output_bytes = [0; 1_000];
output_reader.fill(&mut output_bytes);
// Double check the answer.
let mut hasher = Hasher::new();
hasher.update(chunk0);
hasher.update(chunk1);
let mut expected = [0; 1_000];
hasher.finalize_xof().fill(&mut expected);
assert_eq!(output_bytes, expected);