Wire up hasher options, but hard code sip for now

This commit is contained in:
Jon Moroney 2025-08-25 19:49:25 -07:00
parent aac9046fbf
commit 231aff7062
No known key found for this signature in database
GPG key ID: 0DE20E0350BECFF2
3 changed files with 15 additions and 4 deletions

2
Cargo.lock generated
View file

@ -113,7 +113,7 @@ dependencies = [
[[package]]
name = "ddh"
version = "0.12.0"
version = "0.13.0"
dependencies = [
"clap",
"nohash-hasher",

View file

@ -14,6 +14,11 @@ pub enum HashMode {
Partial,
}
pub enum HashAlgoEnum {
Sip128,
Sha256,
}
/// Serializable struct containing entries for a specific file. These structs will identify individual files as a collection of paths and associated hash and length data.
#[derive(Debug)]
pub struct Fileinfo {
@ -155,7 +160,12 @@ impl Fileinfo {
&self.file_paths
}
pub fn generate_hash(&mut self, mode: HashMode) -> Option<u128> {
pub fn generate_hash(&mut self, mode: HashMode, hash_algo: HashAlgoEnum) -> Option<u128> {
let mut hasher;
match hash_algo {
HashAlgoEnum::Sip128 => hasher = siphasher::sip128::SipHasher::new(),
_ => hasher = siphasher::sip128::SipHasher::new(),
}
let mut hasher = siphasher::sip128::SipHasher::new();
match fs::File::open(
self.file_paths

View file

@ -11,6 +11,7 @@ use std::collections::hash_map::{Entry, HashMap};
use std::fs::{self, DirEntry};
use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Sender};
use crate::fileinfo::HashAlgoEnum;
enum ChannelPackage {
Success(Fileinfo),
@ -131,7 +132,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
1 => return files,
n if n > 1 => {
files.par_iter_mut().for_each(|file_ref| {
let hash = file_ref.generate_hash(HashMode::Partial);
let hash = file_ref.generate_hash(HashMode::Partial, HashAlgoEnum::Sip128);
file_ref.set_partial_hash(hash);
});
if file_length <= 4096 {
@ -158,7 +159,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
.collect();
files.par_iter_mut().for_each(|x| {
if dedupe_hashes.contains(&x.get_partial_hash()) {
let hash = x.generate_hash(HashMode::Full);
let hash = x.generate_hash(HashMode::Full, HashAlgoEnum::Sip128);
x.set_full_hash(hash);
}
});