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.
This commit is contained in:
parent
6426e59c63
commit
95ad91cdb6
|
@ -26,12 +26,6 @@ macro_rules! hash_trait_impls {
|
||||||
#[cfg(not(feature = "hex"))]
|
#[cfg(not(feature = "hex"))]
|
||||||
$crate::impl_debug_only!(Hash, { $bits / 8 }, $reverse $(, $gen: $gent)*);
|
$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")]
|
#[cfg(feature = "serde")]
|
||||||
$crate::serde_impl!(Hash, { $bits / 8} $(, $gen: $gent)*);
|
$crate::serde_impl!(Hash, { $bits / 8} $(, $gen: $gent)*);
|
||||||
|
|
||||||
|
|
|
@ -208,52 +208,6 @@ pub trait HashEngine: Clone {
|
||||||
fn finalize(self) -> Self::Hash;
|
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<B, I>(byte_slices: I) -> Self
|
|
||||||
where
|
|
||||||
B: AsRef<[u8]>,
|
|
||||||
I: IntoIterator<Item = B>,
|
|
||||||
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.
|
/// Trait which applies to hashes of all types.
|
||||||
pub trait Hash:
|
pub trait Hash:
|
||||||
Copy + Clone + PartialEq + Eq + PartialOrd + Ord + hash::Hash + convert::AsRef<[u8]>
|
Copy + Clone + PartialEq + Eq + PartialOrd + Ord + hash::Hash + convert::AsRef<[u8]>
|
||||||
|
|
Loading…
Reference in New Issue