| Crates.io | noncrypto-digests |
| lib.rs | noncrypto-digests |
| version | 0.3.6 |
| created_at | 2023-12-08 06:55:12.472725+00 |
| updated_at | 2025-06-08 03:49:19.99016+00 |
| description | Implement Digest trait for non-cryptographic hashing functions like fnv and xxhash |
| homepage | |
| repository | https://github.com/nyurik/noncrypto-digests |
| max_upload_size | |
| id | 1061663 |
| size | 44,566 |
Implement digest::Digest trait for non-cryptographic hashing functions like fnv and xxhash. This allows users to use all cryptographic and non-cryptographic hashing functions polymorphically.
use digest::Digest;
use hex::ToHex;
use noncrypto_digests::{Fnv, Xxh3_64, Xxh3_128, Xxh32, Xxh64};
/// This function takes any Digest type, and returns a hex-encoded string.
pub fn hash<T: Digest>(data: impl AsRef<[u8]>) -> String {
// Note that some hashers provide seed value set to 0 by default.
// Use `...::from_hasher(hasher)` function to instantiate them.
let mut hasher = T::new();
hasher.update(data);
hasher.finalize().to_vec().encode_hex_upper()
}
assert_eq!(hash::<Fnv>("password"), "4B1A493507B3A318");
assert_eq!(hash::<Xxh3_64>("password"), "336576D7E0E06F9A");
assert_eq!(hash::<Xxh3_128>("password"), "9CFA9055952177DA0B120BE86072A8F0");
assert_eq!(hash::<Xxh32>("password"), "106C6CED");
assert_eq!(hash::<Xxh64>("password"), "90007DAF3980EF1F");
make.
Install it with cargo install just.just.just test.Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.