I'm trying to implement iterated SHA256. This works:
use sha2::{Digest, Sha256}; // 0.8.2
fn main() {
let preimage = [42; 80];
let hash = Sha256::digest(&Sha256::digest(&preimage));
}
This doesn't:
use sha2::{Digest, Sha256}; // 0.8.2
fn main() {
let preimage = [42; 80];
let mut hash = preimage;
for _ in 0..2 {
hash = Sha256::digest(&hash);
}
}
I get an error:
error[E0308]: mismatched types
--> src/main.rs:7:16
|
7 | hash = Sha256::digest(&hash);
| ^^^^^^^^^^^^^^^^^^^^^ expected array `[u8; 80]`, found struct `generic_array::GenericArray`
|
= note: expected array `[u8; 80]`
found struct `generic_array::GenericArray<u8, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>`
I would like the second style so I can easily re-iterate more than twice.