Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3eb8d2d

Browse files
committed
Auto merge of rust-lang#134134 - purplesyringa:hash-str-with-length-prefix, r=<try>
Use length prefix in default `Hasher::write_str` Using a 0xFF trailer is only correct for bytewise hashes. A generic `Hasher` is not necessarily bytewise, so use a length prefix in the default implementation instead. Context: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/collision-free.20non-bytewise.20hashers.20on.20stable r? saethlin
2 parents 33c245b + 88a9534 commit 3eb8d2d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ pub trait Hasher {
549549
#[inline]
550550
#[unstable(feature = "hasher_prefixfree_extras", issue = "96762")]
551551
fn write_str(&mut self, s: &str) {
552+
self.write_length_prefix(s.len());
552553
self.write(s.as_bytes());
553-
self.write_u8(0xff);
554554
}
555555
}
556556

0 commit comments

Comments
 (0)