From 06b5660031431773b2d130c27871005dc9d1352b Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 5 Mar 2025 18:08:47 +0100 Subject: [PATCH 1/2] Fix `::finish` not being platform agnostic --- src/sip128.rs | 2 +- src/stable_hasher/tests.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sip128.rs b/src/sip128.rs index 19dd060..6b5d79b 100644 --- a/src/sip128.rs +++ b/src/sip128.rs @@ -529,7 +529,7 @@ impl Hasher for SipHasher128 { }; // Combining the two halves makes sure we get a good quality hash. - a.wrapping_mul(3).wrapping_add(b).to_le() + a.wrapping_mul(3).wrapping_add(b) } } diff --git a/src/stable_hasher/tests.rs b/src/stable_hasher/tests.rs index 470a183..b2f2946 100644 --- a/src/stable_hasher/tests.rs +++ b/src/stable_hasher/tests.rs @@ -133,3 +133,23 @@ fn test_cloned_hasher_output() { assert_eq!(h1_hash, h2.finish()); assert_ne!(h1_hash, h3.finish()); } + +#[test] +fn test_hash_trait_finish() { + fn hash(h: &H) -> u64 { + h.finish() + } + + // Test that integers are handled consistently across platforms. + let test_u8 = 0xAB_u8; + let test_u16 = 0xFFEE_u16; + let test_u32 = 0x445577AA_u32; + + let mut h1 = StableSipHasher128::new(); + test_u8.hash(&mut h1); + test_u16.hash(&mut h1); + test_u32.hash(&mut h1); + + assert_eq!(hash(&h1), hash(&h1)); + assert_eq!(hash(&h1), 13655241286414701638); +} From 2fa62a70e44d6eb86723518448012b41d07c5091 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 5 Mar 2025 18:11:24 +0100 Subject: [PATCH 2/2] Bump rustc-stable-hash to 0.1.2 --- CHANGELOG.md | 6 ++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8869b0e..7e9254c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Unreleased +# 0.1.2 + +- Fix `::finish` not being platform agnostic [#12][pr12] + +[pr12]: https://github.com/rust-lang/rustc-stable-hash/pull/12 + # 0.1.1 - feat: derive `Clone` for `StableHasher` [#11][pr11] diff --git a/Cargo.lock b/Cargo.lock index 3d98d49..a352b5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "rustc-stable-hash" -version = "0.1.1" +version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index 7841416..e224cdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc-stable-hash" -version = "0.1.1" +version = "0.1.2" description = "A stable hashing algorithm used by rustc" license = "Apache-2.0 OR MIT" readme = "README.md"