feat: use blake2b instead of sha3 for hashing
This commit is contained in:
parent
5b383d22bc
commit
13f0fd4391
|
@ -7,16 +7,17 @@ autoexamples = true
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
blake2 = "0.10"
|
||||
flate2 = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
sha3 = "0.10"
|
||||
sqpack = { git = "https://git.anna.lgbt/ascclemens/sqpack-rs", features = ["read", "write"] }
|
||||
tempfile = "3"
|
||||
thiserror = "1"
|
||||
zip = { version = "0.6", default-features = false, features = ["deflate"] }
|
||||
|
||||
[dev-dependencies]
|
||||
blake2 = "0.10"
|
||||
criterion = "0.4"
|
||||
data-encoding = "2"
|
||||
sha3 = "0.10"
|
||||
|
@ -25,3 +26,6 @@ tempfile = "3"
|
|||
[[bench]]
|
||||
name = "extract"
|
||||
harness = false
|
||||
|
||||
[profile.release]
|
||||
debug = 1
|
||||
|
|
|
@ -3,12 +3,12 @@ use std::fs::File;
|
|||
use std::io::{Seek, SeekFrom};
|
||||
use std::path::Path;
|
||||
|
||||
use sha3::{Digest, Sha3_256};
|
||||
use blake2::{Blake2b, Digest, digest::consts::U32};
|
||||
|
||||
use ttmp::ttmp_extractor::TtmpExtractor;
|
||||
|
||||
pub fn main() {
|
||||
let mut sha = Sha3_256::default();
|
||||
let mut blake = Blake2b::<U32>::default();
|
||||
let arg = std::env::args().skip(1).next().unwrap();
|
||||
let file = File::open(&arg).unwrap();
|
||||
let extractor = TtmpExtractor::new(file).unwrap();
|
||||
|
@ -29,7 +29,6 @@ pub fn main() {
|
|||
for file in files {
|
||||
// handle deduped ttmps
|
||||
if Some(file.file.mod_offset) == last_offset {
|
||||
println!("already seen offset {}", file.file.mod_offset);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -38,7 +37,6 @@ pub fn main() {
|
|||
temp.set_len(0).unwrap();
|
||||
temp.seek(SeekFrom::Start(0)).unwrap();
|
||||
|
||||
println!("{:#?}", file);
|
||||
// write each file into a temp file, then hash
|
||||
// mod files can get quite large, so storing them entirely in memory is probably a bad idea
|
||||
// let mut cursor = Cursor::new(Vec::with_capacity(file.file.mod_size));
|
||||
|
@ -52,9 +50,9 @@ pub fn main() {
|
|||
// let data = cursor.into_inner();
|
||||
// sha.update(&data);
|
||||
temp.seek(SeekFrom::Start(0)).unwrap();
|
||||
std::io::copy(&mut temp, &mut sha).unwrap();
|
||||
std::io::copy(&mut temp, &mut blake).unwrap();
|
||||
temp.seek(SeekFrom::Start(0)).unwrap();
|
||||
let hash = sha.finalize_reset();
|
||||
let hash = blake.finalize_reset();
|
||||
let hash = data_encoding::BASE64URL_NOPAD.encode(&*hash);
|
||||
let new = !hashes.contains_key(&hash);
|
||||
let saved = SavedFile {
|
||||
|
@ -66,12 +64,11 @@ pub fn main() {
|
|||
|
||||
if new {
|
||||
let path = Path::new("files").join(&hash);
|
||||
println!("writing {}", path.to_string_lossy());
|
||||
std::io::copy(&mut temp, &mut File::create(&path).unwrap()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
println!("{:#?}", hashes);
|
||||
println!("done");
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -2,9 +2,9 @@ use std::collections::{HashMap, HashSet};
|
|||
use std::fs::File;
|
||||
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
|
||||
|
||||
use blake2::{Blake2b, Digest, digest::consts::U32};
|
||||
use flate2::Compression;
|
||||
use flate2::write::DeflateEncoder;
|
||||
use sha3::{Digest, Sha3_384};
|
||||
use sqpack::{DatBlockHeader, DatStdFileBlockInfos, FileKind, LodBlock, ModelBlock, SqPackFileInfo, SqPackFileInfoHeader};
|
||||
use sqpack::binrw::{self, BinWriterExt};
|
||||
|
||||
|
@ -134,7 +134,7 @@ impl MpdEncoder {
|
|||
const HEADER_SIZE: usize = std::mem::size_of::<RawTextureHeader>();
|
||||
|
||||
let mut buf = [0; Self::BLOCK_SIZE];
|
||||
let mut hasher = Sha3_384::default();
|
||||
let mut hasher = Blake2b::<U32>::default();
|
||||
|
||||
// read the texture file's header
|
||||
let header: RawTextureHeader = read_struct(&mut data, &mut buf)?;
|
||||
|
@ -297,7 +297,7 @@ impl MpdEncoder {
|
|||
}
|
||||
|
||||
let mut buf = [0; Self::BLOCK_SIZE];
|
||||
let mut hasher = Sha3_384::default();
|
||||
let mut hasher = Blake2b::<U32>::default();
|
||||
|
||||
// read the model file's header
|
||||
let header: RawModelHeader = read_struct(&mut data, &mut buf)?;
|
||||
|
@ -510,7 +510,7 @@ impl MpdEncoder {
|
|||
let after_header = self.writer.stream_position().map_err(Error::Io)?;
|
||||
|
||||
// write the data
|
||||
let mut hasher = Sha3_384::default();
|
||||
let mut hasher = Blake2b::<U32>::default();
|
||||
let infos = self.write_blocks(data, &mut hasher)?;
|
||||
let hash = hasher.finalize();
|
||||
|
||||
|
|
Loading…
Reference in New Issue