hashes: Call through to trait methods

Currently we have duplicate code in inherent functions that also occurs
in the default implementation of the `GeneralHash` trait methods, this
is unnecessary because we can call through to the trait methods.
This commit is contained in:
Tobin C. Harding 2024-07-21 22:57:35 +10:00
parent 5cca2f271d
commit 975f22f399
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 4 additions and 26 deletions

View File

@ -186,13 +186,7 @@ macro_rules! hash_type {
/// Hashes some bytes.
#[allow(clippy::self_named_constructors)] // Hash is a noun and a verb.
pub fn hash(data: &[u8]) -> Self {
use $crate::HashEngine;
let mut engine = Self::engine();
engine.input(data);
Self::from_engine(engine)
}
pub fn hash(data: &[u8]) -> Self { <Self as crate::GeneralHash>::hash(data) }
/// Hashes all the byte slices retrieved from the iterator together.
pub fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
@ -200,13 +194,7 @@ macro_rules! hash_type {
B: AsRef<[u8]>,
I: IntoIterator<Item = B>,
{
use $crate::HashEngine;
let mut engine = Self::engine();
for slice in byte_slices {
engine.input(slice.as_ref());
}
Self::from_engine(engine)
<Self as crate::GeneralHash>::hash_byte_chunks(byte_slices)
}
/// Returns the underlying byte array.

View File

@ -209,11 +209,7 @@ macro_rules! sha256t_hash_newtype {
/// Hashes some bytes.
#[allow(unused)] // the user of macro may not need this
pub fn hash(data: &[u8]) -> Self {
use $crate::HashEngine;
let mut engine = Self::engine();
engine.input(data);
Self::from_engine(engine)
<$hash_name as $crate::GeneralHash>::hash(data)
}
/// Hashes all the byte slices retrieved from the iterator together.
@ -223,13 +219,7 @@ macro_rules! sha256t_hash_newtype {
B: AsRef<[u8]>,
I: IntoIterator<Item = B>,
{
use $crate::HashEngine;
let mut engine = Self::engine();
for slice in byte_slices {
engine.input(slice.as_ref());
}
Self::from_engine(engine)
<$hash_name as $crate::GeneralHash>::hash_byte_chunks(byte_slices)
}
}