Skip to content

Fix <StableSipHasher128 as Hasher>::finish not being platform agnostic #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

# 0.1.2

- Fix `<StableSipHasher128 as Hasher>::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]
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/sip128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/stable_hasher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: Hasher>(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);
}