Merge rust-bitcoin/rust-bitcoin#3127: hashes: Call through to trait methods

975f22f399 hashes: Call through to trait methods (Tobin C. Harding)

Pull request description:

  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.

ACKs for top commit:
  Kixunil:
    ACK 975f22f399
  apoelstra:
    ACK 975f22f399 successfully ran local tests

Tree-SHA512: 74d8905a20d75536abf477dd2226e3cb12d8bd7330b1769e520840df1538362c6cbec6a976dfeb771797732b1f9259ee4f1970cadb69eca67b8b9bbe956ceeca
This commit is contained in:
merge-script 2024-08-06 16:58:59 +00:00
commit 075ab9d3e0
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 4 additions and 26 deletions

View File

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

View File

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