diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs index 41ffab593..fee359a9e 100644 --- a/hashes/src/internal_macros.rs +++ b/hashes/src/internal_macros.rs @@ -80,6 +80,21 @@ macro_rules! general_hash_type { engine.finalize() } + /// Hashes all the byte slices retrieved from the iterator together. + pub fn hash_byte_chunks(byte_slices: I) -> Hash + where + B: AsRef<[u8]>, + I: IntoIterator, + { + use crate::HashEngine as _; + + let mut engine = Hash::engine(); + for slice in byte_slices { + engine.input(slice.as_ref()); + } + engine.finalize() + } + $crate::internal_macros::hash_type_no_default!($bits, $reverse, $doc); impl Hash { @@ -99,7 +114,7 @@ macro_rules! general_hash_type { B: AsRef<[u8]>, I: IntoIterator, { - ::hash_byte_chunks(byte_slices) + hash_byte_chunks(byte_slices) } } }; diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index be144f2f2..d5acd5edf 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -21,6 +21,22 @@ where engine.finalize() } +/// Hashes all the byte slices retrieved from the iterator together. +pub fn hash_byte_chunks(byte_slices: I) -> Hash +where + B: AsRef<[u8]>, + I: IntoIterator, + T: Tag, +{ + use crate::HashEngine as _; + + let mut engine = HashEngine::default(); + for slice in byte_slices { + engine.input(slice.as_ref()); + } + engine.finalize() +} + /// Trait representing a tag that can be used as a context for SHA256t hashes. pub trait Tag { /// The [`Midstate`] after pre-tagging the hash engine.