Implement ContentHash for u32 and u64

This is for completeness and to avoid accidents such as someone calling
`ContentHash::hash(1234u32.to_le_bytes())` and expecting it to hash properly as
a u32 instead of a 4 byte slice, which produces a different hash due to hashing
the length of the slice before its contents.
This commit is contained in:
Evan Mesterhazy 2024-02-16 09:28:30 -05:00 committed by Evan Mesterhazy
parent e1fd402d39
commit a80d0183a2

View file

@ -39,12 +39,24 @@ impl ContentHash for u8 {
}
}
impl ContentHash for u32 {
fn hash(&self, state: &mut impl digest::Update) {
state.update(&self.to_le_bytes());
}
}
impl ContentHash for i32 {
fn hash(&self, state: &mut impl digest::Update) {
state.update(&self.to_le_bytes());
}
}
impl ContentHash for u64 {
fn hash(&self, state: &mut impl digest::Update) {
state.update(&self.to_le_bytes());
}
}
impl ContentHash for i64 {
fn hash(&self, state: &mut impl digest::Update) {
state.update(&self.to_le_bytes());