added sha256::compute_slice_iter

tokio-1.0
Avril 3 years ago
parent 4e1d21b7d7
commit 2e3ff12cb7
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "cryptohelpers"
version = "1.7.0"
version = "1.7.1"
license= "MIT"
description = "Collection of helpers and simplifying functions for cryptography things"
authors = ["Avril <flanchan@cumallover.me>"]

@ -122,6 +122,21 @@ where T: AsyncRead + Unpin + ?Sized
}
/// Compute SHA256 hash from an iterator of slices.
pub fn compute_slice_iter<T, I>(from: I) -> Sha256Hash
where T: AsRef<[u8]>,
I: IntoIterator<Item=T>
{
let mut hasher = Sha256::new();
for from in from.into_iter()
{
hasher.update(from.as_ref());
}
let mut hash = [0u8; SIZE];
bytes::copy_slice(&mut hash, &hasher.finalize());
Sha256Hash{hash}
}
/// Compute SHA256 hash from a slice.
pub fn compute_slice<T>(from: T) -> Sha256Hash
where T: AsRef<[u8]>

Loading…
Cancel
Save