/rust/registry/src/index.crates.io-1949cf8c6b5b557f/blake3-1.8.4/src/guts.rs
Line | Count | Source |
1 | | //! Deprecated in favor of [`hazmat`](crate::hazmat) |
2 | | |
3 | | pub use crate::{BLOCK_LEN, CHUNK_LEN}; |
4 | | |
5 | | #[derive(Clone, Debug)] |
6 | | pub struct ChunkState(crate::ChunkState); |
7 | | |
8 | | impl ChunkState { |
9 | | // Currently this type only supports the regular hash mode. If an |
10 | | // incremental user needs keyed_hash or derive_key, we can add that. |
11 | 0 | pub fn new(chunk_counter: u64) -> Self { |
12 | 0 | Self(crate::ChunkState::new( |
13 | 0 | crate::IV, |
14 | 0 | chunk_counter, |
15 | 0 | 0, |
16 | 0 | crate::platform::Platform::detect(), |
17 | 0 | )) |
18 | 0 | } |
19 | | |
20 | | #[inline] |
21 | 0 | pub fn len(&self) -> usize { |
22 | 0 | self.0.count() |
23 | 0 | } |
24 | | |
25 | | #[inline] |
26 | 0 | pub fn update(&mut self, input: &[u8]) -> &mut Self { |
27 | 0 | self.0.update(input); |
28 | 0 | self |
29 | 0 | } |
30 | | |
31 | 0 | pub fn finalize(&self, is_root: bool) -> crate::Hash { |
32 | 0 | let output = self.0.output(); |
33 | 0 | if is_root { |
34 | 0 | output.root_hash() |
35 | | } else { |
36 | 0 | output.chaining_value().into() |
37 | | } |
38 | 0 | } |
39 | | } |
40 | | |
41 | | // As above, this currently assumes the regular hash mode. If an incremental |
42 | | // user needs keyed_hash or derive_key, we can add that. |
43 | 0 | pub fn parent_cv( |
44 | 0 | left_child: &crate::Hash, |
45 | 0 | right_child: &crate::Hash, |
46 | 0 | is_root: bool, |
47 | 0 | ) -> crate::Hash { |
48 | 0 | let output = crate::parent_node_output( |
49 | 0 | left_child.as_bytes(), |
50 | 0 | right_child.as_bytes(), |
51 | 0 | crate::IV, |
52 | | 0, |
53 | 0 | crate::platform::Platform::detect(), |
54 | | ); |
55 | 0 | if is_root { |
56 | 0 | output.root_hash() |
57 | | } else { |
58 | 0 | output.chaining_value().into() |
59 | | } |
60 | 0 | } |