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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Hash provider abstraction for identity operations
//!
//! This module provides a trait-based abstraction for hashing operations,
//! allowing the core-identity crate to remain decoupled from specific
//! hash implementations.
use blake3;
/// Hash provider trait for identity operations
///
/// This trait abstracts the hashing algorithm used for identity operations,
/// following the Dependency Inversion Principle (DIP). The core identity
/// logic depends on this abstraction rather than concrete implementations.
///
/// ## Design Rationale
///
/// - **Decoupling**: Core identity logic doesn't depend on Blake3 directly
/// - **Testability**: Can use mock hash providers in tests
/// - **Flexibility**: Easy to switch hash algorithms if needed
/// - **Future-proofing**: Supports quantum-resistant hashes in the future
/// Default Blake3 hash provider
///
/// This is the default implementation using Blake3, a fast cryptographic
/// hash function. Blake3 provides:
///
/// - **Speed**: Faster than SHA-256, SHA-3, and BLAKE2
/// - **Security**: 256-bit security level
/// - **Simplicity**: Single-pass, no configuration needed
/// - **Parallelism**: Can leverage multiple cores
///
/// ## Example
///
/// ```
/// use core_identity::hash::{HashProvider, Blake3HashProvider};
///
/// let provider = Blake3HashProvider;
/// let hash = provider.hash(b"Hello, world!");
/// assert_eq!(hash.len(), 32);
/// ```
;
/// Global hash provider instance
///
/// This is the default hash provider used throughout the crate.
/// Currently set to Blake3, but can be changed in the future if needed.
static HASH_PROVIDER: Blake3HashProvider = Blake3HashProvider;
/// Get the current hash provider
///
/// Returns a reference to the global hash provider. This allows
/// the entire crate to use a consistent hashing algorithm.
///
/// ## Example
///
/// ```
/// use core_identity::hash::{hash_provider, HashProvider};
///
/// let provider = hash_provider();
/// let hash = provider.hash(b"data");
/// ```
/// Convenience function for hashing data
///
/// This is a shorthand for `hash_provider().hash(data)`.
///
/// ## Example
///
/// ```
/// use core_identity::hash::hash;
///
/// let digest = hash(b"Hello, world!");
/// assert_eq!(digest.len(), 32);
/// ```