Skip to content

Commit 5558fa4

Browse files
committed
add a guts docs example
1 parent 1a6c1e2 commit 5558fa4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

rust/guts/src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
//! # The BLAKE3 Guts API
2+
//!
3+
//! See `readme.md`.
4+
//!
5+
//! The main entrypoint into this crate is [`DETECTED_IMPL`], which is a global [`Implementation`]
6+
//! that atomically initializes itself the first time you use it.
7+
//!
8+
//! # Example
9+
//!
10+
//! ```rust
11+
//! use blake3_guts::{TransposedVectors, DETECTED_IMPL, IV_BYTES, PARENT, ROOT};
12+
//!
13+
//! // Hash an input of exactly two chunks.
14+
//! let input = [0u8; 2048];
15+
//! let mut outputs = TransposedVectors::new();
16+
//! let (left_outputs, _) = DETECTED_IMPL.split_transposed_vectors(&mut outputs);
17+
//! DETECTED_IMPL.hash_chunks(
18+
//! &input,
19+
//! &IV_BYTES,
20+
//! 0, // counter
21+
//! 0, // flags
22+
//! left_outputs,
23+
//! );
24+
//! let root_node = outputs.extract_parent_node(0);
25+
//! let hash = DETECTED_IMPL.compress(
26+
//! &root_node,
27+
//! 64, // block_len
28+
//! &IV_BYTES,
29+
//! 0, // counter
30+
//! PARENT | ROOT,
31+
//! );
32+
//!
33+
//! // Compute the same hash using the reference implementation.
34+
//! let mut reference_hasher = reference_impl::Hasher::new();
35+
//! reference_hasher.update(&input);
36+
//! let mut expected_hash = [0u8; 32];
37+
//! reference_hasher.finalize(&mut expected_hash);
38+
//!
39+
//! assert_eq!(hash, expected_hash);
40+
//! ```
41+
142
// Tests always require libstd.
243
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
344

0 commit comments

Comments
 (0)