hashes: Add Hash::from_byte_chunks to construct hashes from iterators

This commit is contained in:
Steven Roose 2023-12-10 18:03:52 +00:00
parent b81faab33d
commit 94a6caf204
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
1 changed files with 13 additions and 0 deletions

View File

@ -197,6 +197,19 @@ pub trait Hash:
Self::from_engine(engine) 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>,
{
let mut engine = Self::engine();
for slice in byte_slices {
engine.input(slice.as_ref());
}
Self::from_engine(engine)
}
/// Flag indicating whether user-visible serializations of this hash /// Flag indicating whether user-visible serializations of this hash
/// should be backward. For some reason Satoshi decided this should be /// should be backward. For some reason Satoshi decided this should be
/// true for `Sha256dHash`, so here we are. /// true for `Sha256dHash`, so here we are.