I'm new to rust I'm finished reading chapter 1 of the purple crab book and I'm stuck.
I'm using this crate for sha1 https://docs.rs/sha-1/0.9.1/sha1/
I want to return the output of m.finalize(); How do I achieve this in rust?
in python I'd do something like this
def gen_chain():
chain_redux = "some_Str"
hash = None
hasher = Sha1()
for i in range(0,iterations):
hasher.update(chain_redux)
hash = hasher.finalize()
hasher.reset()
chain_redux = redux(hash)
print(chain_redux)
return hash
Heres what I have in rust
fn calc_chain(name_table:&Vec<String> ,iterations:i32) -> GenericArray<u8, <sha1::Sha1 as Digest>::OutputSize>{
let mut m = sha1::Sha1::new();
let mut chain_redux = &name_table[0];
let mut hash;
// The above doesnt fly in rust. and i can't figure out how to make the arr! macro return a
// GenericArray<u8, <sha1::Sha1 as Digest>::OutputSize> I also don't know if I should.
for i in 0..iterations {
println!("Curr string: {}",chain_redux);
m.update(chain_redux);
hash = m.finalize(); // let hash = m.finalize() here keeps me from returning it because rust
// deletes it after the for loop scope
m.reset();
chain_redux = redux(&hash, name_table);
println!("Redux Output: {}",chain_redux);
};
hash
}
Any rust tips/pointers would be appreciated here also.