blob: 32102f2a97464fb6216e7f7e7d3bf5dc8e64d936 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use sha2::{Digest, Sha256};
fn main() {
let blobs = Blobs::new(128 * 1024);
for blob in blobs.take(10) {
println!("{}", sha256(&blob));
}
}
struct Blobs {
size: usize,
}
impl Blobs {
fn new(size: usize) -> Self {
Self { size }
}
}
impl Iterator for Blobs {
type Item = Vec<u8>;
fn next(&mut self) -> Option<Self::Item> {
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)
}
|