Crate rattler_digest
source ·Expand description
A module that provides utility functions for computing hashes using the RustCrypto/hashes library.
This module provides several functions that wrap around the hashing algorithms provided by the
RustCrypto
library. These functions allow you to easily compute the hash of a file, or a
stream of bytes using a variety of hashing algorithms.
By utilizing the Digest
trait, any hashing algorithm that implements that trait can be used
with the functions provided in this crate.
§Examples
use rattler_digest::{compute_bytes_digest, compute_file_digest};
use sha2::Sha256;
use md5::Md5;
// Compute the MD5 hash of a string
let md5_result = compute_bytes_digest::<Md5>("Hello, world!");
println!("MD5 hash: {:x}", md5_result);
// Compute the SHA256 hash of a file
let sha256_result = compute_file_digest::<Sha256>("somefile.txt").unwrap();
println!("SHA256 hash: {:x}", sha256_result);
§Available functions
compute_file_digest
: Computes the hash of a file on disk.parse_digest_from_hex
: Given a hex representation of a digest, parses it to bytes.HashingWriter
: An object that wraps a writable object and implementsWrite
and [::tokio::io::AsyncWrite
]. It forwards the data to the wrapped object but also computes the hash of the content on the fly.
For more information on the hashing algorithms provided by the RustCrypto/hashes library, see the documentation for that library.
Re-exports§
pub use digest;
Structs§
- A simple object that provides a
Read
implementation that also immediately hashes the bytes read from it. CallHashingReader::finalize
to retrieve both the originalimpl Read
object as well as the hash. - A simple object that provides a
Write
implementation that also immediately hashes the bytes written to it. CallHashingWriter::finalize
to retrieve both the originalimpl Write
object as well as the hash.
Functions§
- Compute a hash of the specified bytes.
- Compute a hash of the file at the specified location.
- Parses a hash hex string to a digest.
Type Aliases§
- A type for a 32 bit length blake2b digest.
- A type alias for the output of a
Blake2b256
hash. - A type alias for the output of a blake2b256 hash.
- A type alias for the output of a
Blake2bMac256
hash. - MD5 hasher state.
- A type alias for the output of an MD5 hash.
- SHA-256 hasher.
- A type alias for the output of a SHA256 hash.