1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Cryptographic hashing to produce content addresses.
use crateVctrlError;
use crateHash;
/// Defines the interface for hashing raw data into a [`Hash`].
///
/// # Purpose
///
/// A `Hasher` implements the specific content-addressing algorithm (e.g.,
/// SHA-256, BLAKE3) used to identify objects in the system.
///
/// # Design Rationale
///
/// The `hash` method does not return a `Result` because hashing pure byte
/// slices is an infallible operation. It takes `&self` to allow stateful
/// hashers or those initialized with specific keys.
///
/// # Examples
///
/// ```
/// use libvctrl_handler::{Blob, Hash, Hasher, VctrlError};
///
/// struct DummyHasher;
/// impl Hasher for DummyHasher {
/// fn hash(&self, _data: &[u8]) -> Result<Hash, VctrlError> {
/// Ok(Hash::from_bytes(&[0u8; 64]).unwrap())
/// }
/// }
///
/// let hasher = DummyHasher;
/// let blob = Blob::new(b"hello".to_vec());
/// let hash = hasher.hash(blob.data()).unwrap();
/// assert_eq!(hash.as_bytes(), &[0u8; 64]);
/// ```