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: ACK975f22f399
apoelstra: ACK975f22f399
successfully ran local tests Tree-SHA512: 74d8905a20d75536abf477dd2226e3cb12d8bd7330b1769e520840df1538362c6cbec6a976dfeb771797732b1f9259ee4f1970cadb69eca67b8b9bbe956ceeca
This commit is contained in:
commit
075ab9d3e0
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -227,11 +227,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.
|
||||
|
@ -241,13 +237,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)
|
||||
}
|
||||
|
||||
/// Hashes the entire contents of the `reader`.
|
||||
|
|
Loading…
Reference in New Issue