vios_app 0.1.1

Small JSON vaults: Argon2id + AES-GCM, with optional AAD binding.
Documentation
// โœ… vaultseal_check.rs โ€” VaultSeal Hash Integrity Checker

use std::fs;
use std::path::Path;
use sha2::{Sha256, Digest};

/// ๐Ÿงช Checks if a Vault file's hash matches its registered hash in `.vaultseal`
///
/// # Parameters
/// - `vault_path`: Path to the `.vault` file to verify
///
/// # Returns
/// - `Ok(true)` if hash matches
/// - `Ok(false)` if hash doesn't match
/// - `Err(String)` if file or registry access fails
pub fn check_vaultseal_for_hash(vault_path: &str) -> Result<bool, String> {
    let path = Path::new(vault_path);

    // โœ… Step 1: Read and hash the Vault file
    let contents = fs::read(path)
        .map_err(|e| format!("โŒ Failed to read vault file: {e}"))?;

    let vault_hash_hex = {
        let mut hasher = Sha256::new();
        hasher.update(&contents);
        hex::encode(hasher.finalize())
    };

    // โœ… Step 2: Check if `.vaultseal` registry exists
    let seal_file = Path::new(".vaultseal");
    if !seal_file.exists() {
        return Err("โŒ .vaultseal registry not found.".into());
    }

    // โœ… Step 3: Parse registry and compare hashes
    let seal_contents = fs::read_to_string(seal_file)
        .map_err(|e| format!("โŒ Failed to read .vaultseal file: {e}"))?;

    for line in seal_contents.lines() {
        let parts: Vec<&str> = line.split(',').collect();
        if parts.len() != 3 {
            continue;
        }

        let registered_path = parts[0].trim();
        let registered_hash = parts[2].trim();

        if registered_path == vault_path {
            let is_match = registered_hash == vault_hash_hex;
            return Ok(is_match);
        }
    }

    Err("โŒ Vault path not found in .vaultseal registry.".into())
}