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 implementsWriteand::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;
Modules§
Structs§
- Hashing
Reader - A simple object that provides a
Readimplementation that also immediately hashes the bytes read from it. CallHashingReader::finalizeto retrieve both the originalimpl Readobject as well as the hash. - Hashing
Writer - A simple object that provides a
Writeimplementation that also immediately hashes the bytes written to it. CallHashingWriter::finalizeto retrieve both the originalimpl Writeobject as well as the hash.
Functions§
- compute_
bytes_ digest - Compute a hash of the specified bytes.
- compute_
file_ digest - Compute a hash of the file at the specified location.
- compute_
url_ digest - Compute a hash of the specified Url without basic auth.
- parse_
digest_ from_ hex - Parses a hash hex string to a digest.
Type Aliases§
- Blake2b256
- A type for a 32 bit length blake2b digest.
- Blake2b256
Hash - A type alias for the output of a
Blake2b256hash. - Blake2b
Mac256 - A type alias for the output of a blake2b256 hash.
- Blake2b
Mac256 Hash - A type alias for the output of a
Blake2bMac256hash. - Md5
- MD5 hasher state.
- Md5Hash
- A type alias for the output of an MD5 hash.
- Sha256
- SHA-256 hasher.
- Sha256
Hash - A type alias for the output of a SHA256 hash.