- Rust 100%
| macros | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| readme.md | ||
ninox.rs-digest
A small, no-std hashing / digest library supporting many usefull algorithms.
License
This project is licensed under AGPL-3.0-only. For more informations see the LICENSE file inside the repository here, or alternative online under https://www.gnu.org/licenses/.
Usage
The library uses an central Digest trait that all algorithms must implement.
It's designed with streamability in mind, so you can update the value as many times as you want
and even take an "snapshot" of the digest instead of consuming it outright if you so choose.
use ninox_digest::MD5;
let digest1 = MD5::default()
.update("hello ".as_bytes()) // with .update you can update the digest;
.update("world".as_bytes()) // algorithms even support 1-byte updates!
.finalize(); // Finalize the digest, consuming the MD5 struct
let mut hasher = MD5::default();
hasher.update("hello world".as_bytes());
// Also supports taking the hash at any time and continuing!
let mut buf = [0; MD5::LENGTH];
let digest2 = hasher.digest(&mut buf).unwrap();
hasher.update("!".as_bytes());
assert_eq!(digest1, digest2);
The algorithms itself are feature-gated and need to be activated seperately. Supported algorithms are:
- crc32
- md5
Encodings
The crate supports additionaly some features, that help with formatting / encoding the hashes:
- hexencode: Allows usage of
hexdigestandhexfinalize; results in an hexadecimal string representation of the produced hash.
Zeroing
By default, the zeroize feature is active; it allows algorithms to zero themself on drop, preventing that someone could read the hash afterwards, if they know the memory location. It is advised to keep this behaviour, unless having a VERY good reason to alter / disable it.
Roadmap
This library will evolve over time; in particular, more algorithms will be added:
- sha*
- md4,md6 (lowest priority)
Other areas to work on include:
- adding convienience methods for working with
Iterator<Item = u8>as a update source - implementing
core::io::Write - re-designing the
Digesttrait (or adding a new one) to make it dyn-compatible, or atleast less redundant... - SIMD?
Stability
The crate is currently considered to be UNSTABLE. While the stability of the code itself is considered to be stable to be used in other applications (as in all agorithms are verified to produce the correct results), the crate's interface and the Digest trait are currently NOT.