Skip to content

Commit 21142c9

Browse files
committed
Fix <StableSipHasher128 as Hasher>::finish not being platform agnostic
1 parent 24e9848 commit 21142c9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/sip128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl Hasher for SipHasher128 {
529529
};
530530

531531
// Combining the two halves makes sure we get a good quality hash.
532-
a.wrapping_mul(3).wrapping_add(b).to_le()
532+
a.wrapping_mul(3).wrapping_add(b)
533533
}
534534
}
535535

src/stable_hasher/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,23 @@ fn test_cloned_hasher_output() {
133133
assert_eq!(h1_hash, h2.finish());
134134
assert_ne!(h1_hash, h3.finish());
135135
}
136+
137+
#[test]
138+
fn test_hash_trait_finish() {
139+
fn hash<H: Hasher>(h: &H) -> u64 {
140+
h.finish()
141+
}
142+
143+
// Test that integers are handled consistently across platforms.
144+
let test_u8 = 0xAB_u8;
145+
let test_u16 = 0xFFEE_u16;
146+
let test_u32 = 0x445577AA_u32;
147+
148+
let mut h1 = StableSipHasher128::new();
149+
test_u8.hash(&mut h1);
150+
test_u16.hash(&mut h1);
151+
test_u32.hash(&mut h1);
152+
153+
assert_eq!(hash(&h1), hash(&h1));
154+
assert_eq!(hash(&h1), 13655241286414701638);
155+
}

0 commit comments

Comments
 (0)