Crates.io | threatflux-hashing |
lib.rs | threatflux-hashing |
version | 0.1.8 |
created_at | 2025-08-14 19:36:16.559316+00 |
updated_at | 2025-08-14 19:36:16.559316+00 |
description | High-performance async file hashing library supporting MD5, SHA256, SHA512, and BLAKE3 |
homepage | |
repository | https://github.com/ThreatFlux/threatflux-hashing |
max_upload_size | |
id | 1795486 |
size | 135,090 |
A high-performance async file hashing library for Rust, supporting MD5, SHA256, SHA512, and BLAKE3 algorithms with concurrent processing capabilities.
Add this to your Cargo.toml
:
[dependencies]
threatflux-hashing = "0.1.0"
use threatflux_hashing::calculate_all_hashes;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let hashes = calculate_all_hashes(Path::new("file.bin")).await?;
println!("MD5: {:?}", hashes.md5);
println!("SHA256: {:?}", hashes.sha256);
println!("SHA512: {:?}", hashes.sha512);
println!("BLAKE3: {:?}", hashes.blake3);
Ok(())
}
use threatflux_hashing::{calculate_all_hashes_with_config, HashConfig, HashAlgorithms};
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = HashConfig {
algorithms: HashAlgorithms {
md5: true,
sha256: true,
sha512: false, // Skip SHA512 for speed
blake3: true,
},
buffer_size: 16384, // 16KB buffer
max_concurrent_operations: 20,
};
let hashes = calculate_all_hashes_with_config(Path::new("file.bin"), &config).await?;
Ok(())
}
use threatflux_hashing::calculate_md5;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let md5 = calculate_md5(Path::new("file.bin")).await?;
println!("MD5: {}", md5);
Ok(())
}
use threatflux_hashing::calculate_all_hashes;
use tokio::task::JoinSet;
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let files = vec!["file1.bin", "file2.bin", "file3.bin"];
let mut tasks = JoinSet::new();
for file in files {
tasks.spawn(async move {
calculate_all_hashes(Path::new(file)).await
});
}
while let Some(result) = tasks.join_next().await {
match result {
Ok(Ok(hashes)) => println!("Hashes: {:?}", hashes),
Ok(Err(e)) => eprintln!("Hash error: {}", e),
Err(e) => eprintln!("Task error: {}", e),
}
}
Ok(())
}
max_concurrent_operations
based on your system's capabilitiesAlgorithm | Hash Length | Performance | Use Case |
---|---|---|---|
MD5 | 128 bits | Fast | Legacy compatibility, checksums |
SHA256 | 256 bits | Moderate | General purpose, secure |
SHA512 | 512 bits | Slower | High security requirements |
BLAKE3 | 256 bits | Very Fast | Modern applications |
The library uses custom error types for better error handling:
use threatflux_hashing::{calculate_all_hashes, HashError};
use std::path::Path;
#[tokio::main]
async fn main() {
match calculate_all_hashes(Path::new("nonexistent.bin")).await {
Ok(hashes) => println!("Success: {:?}", hashes),
Err(HashError::Io(e)) => eprintln!("IO Error: {}", e),
Err(e) => eprintln!("Other error: {}", e),
}
}
serde
(default): Enable serialization/deserialization support[dependencies]
threatflux-hashing = { version = "0.1.0", default-features = false }
Licensed under the MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Run benchmarks with:
cargo bench
Typical performance on modern hardware:
Performance varies based on file size, system capabilities, and configuration.