summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-06 11:05:56 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-06 11:05:56 +0300
commit3b0e19ce80536aa98a86a60d8ea17da39f16057c (patch)
treee921f028cc30ac1f2e3b142b356eb5649ea68f17 /src
parent8d968f547c171af8a15f670b4c7b517ef54d27d9 (diff)
downloadchecksum-concurrency-3b0e19ce80536aa98a86a60d8ea17da39f16057c.tar.gz
compute checksums linearly
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
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)
+}