pub type SHA1 = SHA1_Generic;Expand description
The official SHA-1 hash algorithm
§Quick Start
In order to use the module SHA1, you don’t have to import (or use) cryptocol::hash::sha1::SHA1 directly because the module cryptocol::hash::sha1 is re-exported. All you have to do is only import SHA1 in the module cryptocol::hash. The follwing example shows how to import and use SHA1.
§Example
use std::string::*;
use cryptocol::hash::SHA1;
let mut hash = SHA1::new();
let mut txt = "";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash.get_hash_value_in_string());
assert_eq!(hash.get_hash_value_in_string(), "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709");
let txt_stirng = String::from("A");
hash.digest_string(&txt_stirng);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt_stirng, hash);
assert_eq!(hash.to_string(), "6DCD4CE23D88E2EE9568BA546C007C63D9131C1B");
let txt_array = ['W' as u8, 'o' as u8, 'w' as u8];
hash.digest_array(&txt_array);
println!("Msg =\t\"{:?}\"\nHash =\t{}\n", txt_array, hash);
assert_eq!(hash.get_hash_value_in_string(), "0BBCDBD1616A1D2230100F629649DCF5B7A28B7F");
txt = "This data is 26-byte long.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.to_string(), "B82A61505779F6B3ACA4F5E0D54DA44C17375B49");
txt = "The unit of data length is not byte but bit.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.get_hash_value_in_string(), "C6DC54281357FC16D357E1D730BFC313C585DAEC");
txt = "I am testing SHA1 for the data whose length is sixty-two bytes.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.to_string(), "36CD36337097D764797091E5796B6FF45A9FA79F");
txt = "I am testing SHA-1 for the data whose length is sixty-four bytes.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}\n", txt, hash);
assert_eq!(hash.get_hash_value_in_string(), "E408F6B82DCDDB5EE6613A759AC1B13D0FA1CEF1");
txt = "I am testing SHA1 for the case data whose length is more than sixty-four bytes is given.";
hash.digest_str(txt);
println!("Msg =\t\"{}\"\nHash =\t{}", txt, hash);
assert_eq!(hash.to_string(), "BB2C79F551B95963ECE49D40F8A92349BF66CAE7");Aliased Type§
pub struct SHA1 { /* private fields */ }