use std::path::Path;
use std::time::Instant;
use threatflux_hashing::{calculate_all_hashes_with_config, HashAlgorithms, HashConfig};
use tokio::task::JoinSet;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = HashConfig {
algorithms: HashAlgorithms::all(),
buffer_size: 16384, max_concurrent_operations: 20,
};
println!("=== Concurrent File Hashing ===");
let files = vec!["Cargo.toml", "src/lib.rs", "examples/basic_usage.rs"];
let start = Instant::now();
let mut tasks = JoinSet::new();
for file in &files {
let path = Path::new(file).to_path_buf();
let config_clone = config.clone();
tasks.spawn(async move {
let result = calculate_all_hashes_with_config(&path, &config_clone).await;
(path, result)
});
}
while let Some(result) = tasks.join_next().await {
match result {
Ok((path, Ok(hashes))) => {
println!("\nFile: {}", path.display());
println!(" MD5: {:?}", hashes.md5);
println!(" SHA256: {:?}", hashes.sha256);
}
Ok((path, Err(e))) => {
eprintln!("Error hashing {}: {}", path.display(), e);
}
Err(e) => eprintln!("Task error: {}", e),
}
}
println!("\nTotal time: {:?}", start.elapsed());
println!("\n=== Selective Algorithm Hashing ===");
let fast_config = HashConfig {
algorithms: HashAlgorithms {
md5: true,
sha256: false, sha512: false, blake3: true, },
buffer_size: 32768, max_concurrent_operations: config.max_concurrent_operations,
};
let path = Path::new("Cargo.toml");
let start = Instant::now();
let hashes = calculate_all_hashes_with_config(path, &fast_config).await?;
println!("Fast hashing completed in: {:?}", start.elapsed());
println!("MD5: {:?}", hashes.md5);
println!("BLAKE3: {:?}", hashes.blake3);
println!("SHA256: {:?} (skipped)", hashes.sha256);
println!("SHA512: {:?} (skipped)", hashes.sha512);
Ok(())
}