Merge rust-bitcoin/rust-bitcoin#2272: hashes: Add Hash::from_bytes_iter to construct hashes from iterators
94a6caf204
hashes: Add Hash::from_byte_chunks to construct hashes from iterators (Steven Roose) Pull request description: Is there any interest in a method like this? I'm not necessarily a fan myself, was just in a situation where I was doing this a lot and it would save the me the "engine, from_engine dance" each time. ACKs for top commit: Kixunil: ACK94a6caf204
apoelstra: ACK94a6caf204
Tree-SHA512: 96e74366dbf64d50fb6642024d18eeeee5b78154fa152c845a1073c904599af69328a141f0a7e2bd1a7b43a091c886da57dfe6e87bab5a5e01b0f167019caae0
This commit is contained in:
commit
ada8c53ce2
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue