From 3b0e19ce80536aa98a86a60d8ea17da39f16057c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 6 Apr 2021 11:05:56 +0300 Subject: compute checksums linearly --- Cargo.toml | 1 + src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b6c6e6c..31e161f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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) +} -- cgit v1.2.1