From 62617cf9acf880379cfeecb756eb438756d78a23 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 16 Oct 2024 12:00:41 +1100 Subject: [PATCH] hashes: Move from_engine function to other macro The `from_engine` function is associated with a general hash type but we are defining it in the `hash_type` macro which holds nothing but functions associated with the `Hash` trait. By "associated" I mean methods on the type as opposed to trait methods. In preparation for re-naming the `hash_type` macro move the `from_engine` function there. Requires duplicating the code in the `siphash` impl block, this is as expected because the `siphash` requires a custom implementation of the general hashing functionality. Internal change only. --- hashes/src/internal_macros.rs | 6 +++--- hashes/src/siphash24.rs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs index 320b29d7d..4e5f61bd1 100644 --- a/hashes/src/internal_macros.rs +++ b/hashes/src/internal_macros.rs @@ -130,6 +130,9 @@ macro_rules! hash_type { $crate::internal_macros::hash_type_no_default!($bits, $reverse, $doc); impl Hash { + /// Produces a hash from the current state of a given engine. + pub fn from_engine(e: HashEngine) -> Hash { from_engine(e) } + /// Constructs a new engine. pub fn engine() -> HashEngine { Default::default() } @@ -180,9 +183,6 @@ macro_rules! hash_type_no_default { unsafe { &mut *(bytes as *mut _ as *mut Self) } } - /// Produces a hash from the current state of a given engine. - pub fn from_engine(e: HashEngine) -> Hash { from_engine(e) } - /// Copies a byte slice into a hash object. pub fn from_slice( sl: &[u8], diff --git a/hashes/src/siphash24.rs b/hashes/src/siphash24.rs index 1d17885ff..a40f8185c 100644 --- a/hashes/src/siphash24.rs +++ b/hashes/src/siphash24.rs @@ -168,6 +168,9 @@ impl crate::HashEngine for HashEngine { } impl Hash { + /// Produces a hash from the current state of a given engine. + pub fn from_engine(e: HashEngine) -> Hash { from_engine(e) } + /// Hashes the given data with an engine with the provided keys. pub fn hash_with_keys(k0: u64, k1: u64, data: &[u8]) -> Hash { let mut engine = HashEngine::with_keys(k0, k1);