https://github.com/nyurik/noncrypto-digests
Expose various non-cryptographic hashing functions with Digest traits
https://github.com/nyurik/noncrypto-digests
Last synced: 4 months ago
JSON representation
Expose various non-cryptographic hashing functions with Digest traits
- Host: GitHub
- URL: https://github.com/nyurik/noncrypto-digests
- Owner: nyurik
- License: apache-2.0
- Created: 2023-12-08T06:49:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-01T02:40:27.000Z (7 months ago)
- Last Synced: 2025-01-04T20:15:38.239Z (4 months ago)
- Language: Rust
- Size: 27.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# noncrypto-digests
[](https://github.com/nyurik/noncrypto-digests)
[](https://crates.io/crates/noncrypto-digests)
[](https://docs.rs/noncrypto-digests)
[](https://github.com/nyurik/noncrypto-digests/blob/main/LICENSE-APACHE)
[](https://github.com/nyurik/noncrypto-digests/actions)Implement [digest::Digest](https://docs.rs/digest/latest/digest/trait.Digest.html) trait for non-cryptographic hashing functions like fnv and xxhash. This allows users to use all cryptographic and non-cryptographic hashing functions polymorphically.
## Usage
```rust
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(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::("password"), "4B1A493507B3A318");
assert_eq!(hash::("password"), "336576D7E0E06F9A");
assert_eq!(hash::("password"), "9CFA9055952177DA0B120BE86072A8F0");
assert_eq!(hash::("password"), "106C6CED");
assert_eq!(hash::("password"), "90007DAF3980EF1F");
```## Development
* This project is easier to develop with [just](https://github.com/casey/just#readme), a modern alternative to `make`. Install it with `cargo install just`.
* To get a list of available commands, run `just`.
* To run tests, use `just test`.
* On `git push`, it will run a few validations, including `cargo fmt`, `cargo clippy`, and `cargo test`.
Use `git push --no-verify` to skip these checks.## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.### Contribution
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.