rattler_digest 0.1.0

An simple crate used by rattler crates to compute different hashes from different sources
Documentation

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 implements [Write] 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.