From 95ad91cdb64c8870d3eb992090bab7a70d1369b9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 20 Feb 2025 13:57:27 +1100 Subject: [PATCH] hashes: Remove the GeneralHash trait Now that we are able to unambiguously go from a hash engine to its associated hash type there is no longer any need for the `GeneralHash` trait. Please note that IMO this concept of a general hash type as opposed to one where one can hash arbitrary data still exists in the codebase - it is implicitly in the `hash_newtype` macro. Remove the `GeneralHash` trait. --- hashes/src/internal_macros.rs | 6 ----- hashes/src/lib.rs | 46 ----------------------------------- 2 files changed, 52 deletions(-) diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs index fee359a9e..5e9599322 100644 --- a/hashes/src/internal_macros.rs +++ b/hashes/src/internal_macros.rs @@ -26,12 +26,6 @@ macro_rules! hash_trait_impls { #[cfg(not(feature = "hex"))] $crate::impl_debug_only!(Hash, { $bits / 8 }, $reverse $(, $gen: $gent)*); - impl<$($gen: $gent),*> $crate::GeneralHash for Hash<$($gen),*> { - type Engine = HashEngine<$($gen),*>; - - fn from_engine(e: Self::Engine) -> Hash<$($gen),*> { Self::from_engine(e) } - } - #[cfg(feature = "serde")] $crate::serde_impl!(Hash, { $bits / 8} $(, $gen: $gent)*); diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs index 4201b0ea0..b3962214c 100644 --- a/hashes/src/lib.rs +++ b/hashes/src/lib.rs @@ -208,52 +208,6 @@ pub trait HashEngine: Clone { fn finalize(self) -> Self::Hash; } -/// Trait describing hash digests which can be constructed by hashing arbitrary data. -/// -/// Some methods have been bound to engines which implement Default, which is -/// generally an unkeyed hash function. -pub trait GeneralHash: Hash { - /// A hashing engine which bytes can be serialized into. It is expected - /// to implement the `io::Write` trait, and to never return errors under - /// any conditions. - type Engine: HashEngine; - - /// Constructs a new engine. - fn engine() -> Self::Engine - where - Self::Engine: Default, - { - Self::Engine::default() - } - - /// Produces a hash from the current state of a given engine. - fn from_engine(e: Self::Engine) -> Self; - - /// Hashes some bytes. - fn hash(data: &[u8]) -> Self - where - Self::Engine: Default, - { - let mut engine = Self::engine(); - engine.input(data); - Self::from_engine(engine) - } - - /// Hashes all the byte slices retrieved from the iterator together. - fn hash_byte_chunks(byte_slices: I) -> Self - where - B: AsRef<[u8]>, - I: IntoIterator, - Self::Engine: Default, - { - let mut engine = Self::engine(); - for slice in byte_slices { - engine.input(slice.as_ref()); - } - Self::from_engine(engine) - } -} - /// Trait which applies to hashes of all types. pub trait Hash: Copy + Clone + PartialEq + Eq + PartialOrd + Ord + hash::Hash + convert::AsRef<[u8]>