From 88a95348f6a89b595a44d1d7226db95c80fc8242 Mon Sep 17 00:00:00 2001 From: Alisa Sireneva Date: Tue, 10 Dec 2024 19:19:09 +0300 Subject: [PATCH] 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. --- library/core/src/hash/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index 84bbf985e8be4..35b5eed48524f 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -549,8 +549,8 @@ pub trait Hasher { #[inline] #[unstable(feature = "hasher_prefixfree_extras", issue = "96762")] fn write_str(&mut self, s: &str) { + self.write_length_prefix(s.len()); self.write(s.as_bytes()); - self.write_u8(0xff); } }