A More dynamic Hash and Hasher trait for Rust
APACHE-2.0 License
A more dynamic Hash and Hasher trait for Rust
#[digestible(skip)]
#[digestible(type_header = none)]
)no_std
Supportdigest_with
you can add #[digestible(digest_with = digest_with_hash)]
to your variable
to tell Digestible to use Hash to digest it.
Adding #[digestible(hash)]
to your struct or enum will implement Hash for it.
Using the digest function.
Allowing you to have a Hash and Digestible that are the same.
#[derive(Digestible)]
pub struct MyStruct {
pub id: u32,
pub name: String,
#[digestible(skip)]
pub password: String,
}
fn digest_to_bytes(){
let test = MyStruct{
id: 0,
name: "Test".to_string(),
password: "Test".to_string(),
};
let mut hasher = sha2::Sha256::new();
let result = hasher.digest_native(&test); // This will be the type of sha2 Output
}
fn digest_to_base64(){
let test = MyStruct{
id: 0,
name: "Test".to_string(),
password: "Test".to_string(),
};
let hasher = sha2::Sha256::new().into_base64();
let result = hasher.digest_native(&test); // This is a base64 encoded string
}