diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 11 insertions, 1 deletions
@@ -7,3 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +sha2 = "0.9.3" diff --git a/src/main.rs b/src/main.rs index b37873b..32102f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ +use sha2::{Digest, Sha256}; + fn main() { let blobs = Blobs::new(128 * 1024); for blob in blobs.take(10) { - println!("{}", blob.len()); + println!("{}", sha256(&blob)); } } @@ -22,3 +24,10 @@ impl Iterator for Blobs { Some(vec![0; self.size]) } } + +fn sha256(data: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(data); + let hash = hasher.finalize(); + format!("{:x}", hash) +} |