Skip to content

Commit c23d922

Browse files
authored
feat: impl Hash for Mutlihash<S> (#93)
`Multihash` now implements `Hash`. It is using the actual digest and not the whole allocated space for hashing.
1 parent 6aee074 commit c23d922

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/multihash.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ impl<S: Size> Multihash<S> {
163163
}
164164
}
165165

166+
// Don't hash the whole allocated space, but just the actual digest
167+
#[allow(clippy::derive_hash_xor_eq)]
168+
impl<S: Size> core::hash::Hash for Multihash<S> {
169+
fn hash<T: core::hash::Hasher>(&self, state: &mut T) {
170+
self.code.hash(state);
171+
self.digest().hash(state);
172+
}
173+
}
174+
166175
#[cfg(feature = "std")]
167176
impl<S: Size> From<Multihash<S>> for Vec<u8> {
168177
fn from(multihash: Multihash<S>) -> Self {

0 commit comments

Comments
 (0)