Skip to content

Commit 88a9534

Browse files
committed
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.
1 parent 33c245b commit 88a9534

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)