A more dynamic Hash and Hasher trait for Rust
- ByteOrder is built in. So you can digest number types in any byte order. ByteOrder
- Output is a Generic Associated Type. So you can Digest into a ByteArray, String with Base64 or any type the Digester uses.
- Skip Fields with
#[digestible(skip)]
- 'digest_with' and 'with' to override the default digest behavior. digest_with
- Support for all Hashing Algorithms that implement digest::Digest such as SHA2, md-5, and many more.
- Writing Type Headers to prevent collisions with similar types. (This is optional and can be disabled with
#[digestible(type_header = none)]
)
no_std
Support- Digest to implement Digester for all types that implement digest::Digest
- Float and Atomic Support using
digest_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
}