feat: initial implementation of content-addressed incremental backup engine
Rust-centric architecture with TypeScript facade following smartproxy/smartstorage pattern. Core engine in Rust (FastCDC chunking, SHA-256, gzip, AES-256-GCM + Argon2id, binary pack files, global index, snapshots, locking, verification, pruning, repair). TypeScript provides npm interface via @push.rocks/smartrust RustBridge IPC with Unix socket streaming for ingest/restore. All 14 integration tests pass.
This commit is contained in:
97
rust/src/config.rs
Normal file
97
rust/src/config.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RepositoryConfig {
|
||||
pub version: u32,
|
||||
pub id: String,
|
||||
pub created_at: String,
|
||||
pub chunking: ChunkingConfig,
|
||||
pub compression: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub encryption: Option<EncryptionConfig>,
|
||||
pub pack_target_size: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChunkingConfig {
|
||||
pub algorithm: String,
|
||||
pub min_size: u32,
|
||||
pub avg_size: u32,
|
||||
pub max_size: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EncryptionConfig {
|
||||
pub algorithm: String,
|
||||
pub kdf: String,
|
||||
pub kdf_params: KdfParams,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct KdfParams {
|
||||
pub memory: u32,
|
||||
pub iterations: u32,
|
||||
pub parallelism: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct KeyFile {
|
||||
pub id: String,
|
||||
pub created_at: String,
|
||||
pub kdf: String,
|
||||
pub kdf_salt: String,
|
||||
pub kdf_params: KdfParams,
|
||||
pub encrypted_key: String,
|
||||
pub nonce: String,
|
||||
pub auth_tag: String,
|
||||
}
|
||||
|
||||
impl Default for ChunkingConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
algorithm: "fastcdc".to_string(),
|
||||
min_size: 65536, // 64 KB
|
||||
avg_size: 262144, // 256 KB
|
||||
max_size: 1048576, // 1 MB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KdfParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
memory: 262144, // 256 MB
|
||||
iterations: 3,
|
||||
parallelism: 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EncryptionConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
algorithm: "aes-256-gcm".to_string(),
|
||||
kdf: "argon2id".to_string(),
|
||||
kdf_params: KdfParams::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RepositoryConfig {
|
||||
pub fn new(encryption: Option<EncryptionConfig>) -> Self {
|
||||
Self {
|
||||
version: 1,
|
||||
id: format!("repo-{}", uuid::Uuid::new_v4()),
|
||||
created_at: chrono::Utc::now().to_rfc3339(),
|
||||
chunking: ChunkingConfig::default(),
|
||||
compression: "gzip".to_string(),
|
||||
encryption,
|
||||
pack_target_size: 8 * 1024 * 1024, // 8 MB
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user