vios_app 0.1.1

Small JSON vaults: Argon2id + AES-GCM, with optional AAD binding.
Documentation
// 🧠 vaultio_loader.rs — Vault Decryption + Memory Rebuilder

use std::fs;
use std::path::Path;

/// Load raw bytes from a file
fn load_bytes(path: &Path) -> Result<Vec<u8>, String> {
    fs::read(path).map_err(|e| format!("Failed to read file {}: {}", path.display(), e))
}

/// Load CIA signature and convert to String
fn load_cia(path: &Path) -> Result<String, String> {
    let bytes = load_bytes(path)?;
    String::from_utf8(bytes).map_err(|e| format!("Invalid UTF-8 in CIA file: {}", e))
}

/// Load Vault metadata and deserialize JSON
fn load_metadata(path: &Path) -> Result<VaultMetadata, String> {
    let json_str = fs::read_to_string(path)
        .map_err(|e| format!("Failed to read metadata: {}", e))?;
    serde_json::from_str(&json_str).map_err(|e| format!("Failed to parse metadata JSON: {}", e))
}

/// Load all Vault components from disk
pub fn load_vault_components(vault_path: &str) -> Result<(Vec<u8>, Vec<u8>, Vec<u8>, String, VaultMetadata), String> {
    let path = Path::new(vault_path);

    let ciphertext = load_bytes(path)?;
    let iv = load_bytes(&path.with_extension("iv"))?;
    let salt = load_bytes(&path.with_extension("salt"))?;
    let cia_signature = load_cia(&path.with_extension("cia"))?;
    let metadata = load_metadata(&path.with_extension("meta"))?;

    Ok((ciphertext, iv, salt, cia_signature, metadata))
}