feat: iv and key creation

This commit is contained in:
DecDuck
2025-12-18 19:04:56 +11:00
parent d7f9faf602
commit 5c6597eb6b
4 changed files with 17 additions and 6 deletions
+2 -1
View File
@@ -219,12 +219,13 @@ dependencies = [
[[package]]
name = "droplet-rs"
version = "0.11.2"
version = "0.12.0"
dependencies = [
"anyhow",
"async-trait",
"dyn-clone",
"futures",
"getrandom 0.3.4",
"hex",
"humansize",
"rcgen",
+2 -1
View File
@@ -2,7 +2,7 @@
edition = "2021"
authors = ["Drop-OSS"]
name = "droplet-rs"
version = "0.11.2"
version = "0.12.0"
license = "AGPL-3.0-only"
description = "Droplet is a `napi.rs` Rust/Node.js package full of high-performance and low-level utils for Drop"
@@ -20,6 +20,7 @@ humansize = "2.1.3"
uuid = { version = "1.19.0", features = ["v4"] }
sha2 = "0.10.9"
futures = "0.3.31"
getrandom = "0.3.4"
[dependencies.x509-parser]
version = "0.17.0"
+3 -1
View File
@@ -1,13 +1,14 @@
use std::path::PathBuf;
use droplet_rs::manifest::generate_manifest_rusty;
use serde_json::json;
use tokio::runtime::Handle;
#[tokio::main]
pub async fn main() {
let metrics = Handle::current().metrics();
println!("using {} workers", metrics.num_workers());
generate_manifest_rusty(
let manifest = generate_manifest_rusty(
&PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/Savage Resurrection"),
|progress| {
println!("PROGRESS: {}", progress)
@@ -18,4 +19,5 @@ pub async fn main() {
)
.await
.unwrap();
tokio::fs::write("./manifst.json", json!(manifest).to_string()).await.expect("failed to write manifest");
}
+10 -3
View File
@@ -29,7 +29,7 @@ pub struct FileEntry {
pub struct ChunkData {
files: Vec<FileEntry>,
checksum: String,
//iv: [u8; 16]
iv: [u8; 16],
}
#[derive(Serialize)]
@@ -37,6 +37,7 @@ pub struct Manifest {
version: String,
chunks: HashMap<String, ChunkData>,
size: u64,
key: [u8; 16],
}
const CHUNK_SIZE: u64 = 1024 * 1024 * 64;
@@ -153,10 +154,12 @@ pub async fn generate_manifest_rusty<T: Fn(String), V: Fn(f32)>(
let uuid = uuid::Uuid::new_v4().to_string();
let mut hasher = Sha256::new();
let mut iv = [0u8; 16];
getrandom::fill(&mut iv).map_err(|err| anyhow!("failed to generate IV: {:?}", err))?;
let mut chunk_data = ChunkData {
files: Vec::new(),
checksum: String::new(),
//iv:
iv,
};
let mut chunk_length = 0;
@@ -224,9 +227,13 @@ pub async fn generate_manifest_rusty<T: Fn(String), V: Fn(f32)>(
let manifest = manifest.lock().await;
let manifest = manifest.clone();
let mut key = [0u8; 16];
getrandom::fill(&mut key).map_err(|err| anyhow!("failed to generate key: {:?}", err))?;
Ok(Manifest {
version: "2".to_string(),
chunks: manifest,
size: total_manifest_length.fetch_add(0, Ordering::Relaxed)
size: total_manifest_length.fetch_add(0, Ordering::Relaxed),
key,
})
}