mirror of
https://github.com/darakian/ddh.git
synced 2026-09-10 07:06:21 -04:00
Sha256 working
This commit is contained in:
parent
04f78dd1a7
commit
43018affc4
47
Cargo.lock
generated
47
Cargo.lock
generated
|
|
@ -2,6 +2,18 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
|
|
@ -25,6 +37,19 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3888aaa89e4b2a40fca9848e400f6a658a5a3978de7be858e209cafa8be9a4a0"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
|
|
@ -34,6 +59,15 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
|
@ -77,6 +111,12 @@ dependencies = [
|
|||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
|
|
@ -143,6 +183,7 @@ dependencies = [
|
|||
name = "ddh"
|
||||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"clap",
|
||||
"nohash-hasher",
|
||||
"rayon",
|
||||
|
|
@ -355,6 +396,12 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.9"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ serde_json = "1.0"
|
|||
siphasher = "0.3"
|
||||
nohash-hasher = "0.2"
|
||||
sha2 = "0.10.9"
|
||||
blake3 = "1.8.2"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use siphasher::sip128::Hasher128;
|
|||
use sha2::{Sha256, Digest};
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::{self, Metadata};
|
||||
use std::hash::Hasher;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -18,6 +17,7 @@ pub enum HashMode {
|
|||
pub enum HashAlgoEnum {
|
||||
Sip128,
|
||||
Sha256,
|
||||
Blake3,
|
||||
}
|
||||
|
||||
// pub struct HasherWrapper {
|
||||
|
|
@ -104,7 +104,11 @@ impl Fileinfo {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn get_full_hash(&self) -> Option<Vec<u8>> {
|
||||
self.full_hash
|
||||
self.full_hash.clone()
|
||||
// match self.full_hash {
|
||||
// None => None,
|
||||
// Some(v) => Some(&v),
|
||||
// }
|
||||
}
|
||||
pub(crate) fn set_full_hash(&mut self, hash: Option<Vec<u8>>) {
|
||||
self.full_hash = hash
|
||||
|
|
@ -125,7 +129,11 @@ impl Fileinfo {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn get_partial_hash(&self) -> Option<Vec<u8>> {
|
||||
self.partial_hash
|
||||
self.partial_hash.clone()
|
||||
// match self.partial_hash {
|
||||
// None => None,
|
||||
// Some(v) => Some(v)
|
||||
// }
|
||||
}
|
||||
pub(crate) fn set_partial_hash(&mut self, hash: Option<Vec<u8>>) {
|
||||
self.partial_hash = hash
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
|
|||
});
|
||||
return dedupe(files);
|
||||
}
|
||||
let mut partial_hashes: HashMap<Option<u128>, u64> = HashMap::new();
|
||||
let mut partial_hashes: HashMap<Option<Vec<u8>>, u64> = HashMap::new();
|
||||
files
|
||||
.iter()
|
||||
.for_each(|f| match partial_hashes.entry(f.get_partial_hash()) {
|
||||
|
|
@ -172,7 +172,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
|
|||
}
|
||||
|
||||
fn dedupe(mut files: Vec<Fileinfo>) -> Vec<Fileinfo> {
|
||||
let mut cache: HashMap<(Option<u128>, Option<u128>), &mut Fileinfo> = HashMap::new();
|
||||
let mut cache: HashMap<(Option<Vec<u8>>, Option<Vec<u8>>), &mut Fileinfo> = HashMap::new();
|
||||
files.iter_mut().for_each(|file| {
|
||||
match cache.entry((file.get_partial_hash(), file.get_full_hash())) {
|
||||
Entry::Vacant(e) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue