| 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 |
pub fn new(chunk_counter: u64) -> Self { |
| 12 |
Self(crate::ChunkState::new( |
| 13 |
crate::IV, |
| 14 |
chunk_counter, |
| 15 |
0, |
| 16 |
crate::platform::Platform::detect(), |
| 17 |
)) |
| 18 |
} |
| 19 |
|
| 20 |
#[inline] |
| 21 |
pub fn len(&self) -> usize { |
| 22 |
self.0.count() |
| 23 |
} |
| 24 |
|
| 25 |
#[inline] |
| 26 |
pub fn update(&mut self, input: &[u8]) -> &mut Self { |
| 27 |
self.0.update(input); |
| 28 |
self |
| 29 |
} |
| 30 |
|
| 31 |
pub fn finalize(&self, is_root: bool) -> crate::Hash { |
| 32 |
let output = self.0.output(); |
| 33 |
if is_root { |
| 34 |
output.root_hash() |
| 35 |
} else { |
| 36 |
output.chaining_value().into() |
| 37 |
} |
| 38 |
} |
| 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 |
pub fn parent_cv( |
| 44 |
left_child: &crate::Hash, |
| 45 |
right_child: &crate::Hash, |
| 46 |
is_root: bool, |
| 47 |
) -> crate::Hash { |
| 48 |
let output = crate::parent_node_output( |
| 49 |
left_child.as_bytes(), |
| 50 |
right_child.as_bytes(), |
| 51 |
crate::IV, |
| 52 |
0, |
| 53 |
crate::platform::Platform::detect(), |
| 54 |
); |
| 55 |
if is_root { |
| 56 |
output.root_hash() |
| 57 |
} else { |
| 58 |
output.chaining_value().into() |
| 59 |
} |
| 60 |
} |