mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 23:55:54 +00:00
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:
parent
e1fd402d39
commit
a80d0183a2
1 changed files with 12 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue