vios_app 0.1.1

Small JSON vaults: Argon2id + AES-GCM, with optional AAD binding.
Documentation
// ๐Ÿ” sics_license.rs โ€” Sovereign Intent & Consent System (SICS)
// ============================================================
// ๐Ÿ“œ Attaches licensing + usage rights to each Vault
// Supports: royalty %, expiration, allowed uses, creator info
// ============================================================

use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VaultLicense {
    pub creator: String,           // Wallet or email
    pub allowed_use: String,       // e.g., "personal", "research", "commercial"
    pub royalty_percent: u8,       // 0โ€“100 %
    pub expires_on: Option<String>, // Optional ISO date
    pub notes: Option<String>,     // Human-readable comments
}

impl VaultLicense {
    /// โœ๏ธ new โ€” Create a new license instance
    pub fn new(
        creator: &str,
        allowed_use: &str,
        royalty_percent: u8,
        expires_on: Option<&str>,
        notes: Option<&str>,
    ) -> Self {
        Self {
            creator: creator.to_string(),
            allowed_use: allowed_use.to_string(),
            royalty_percent,
            expires_on: expires_on.map(|s| s.to_string()),
            notes: notes.map(|s| s.to_string()),
        }
    }

    /// ๐Ÿงพ Serialize license as JSON string
    pub fn to_json(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string_pretty(self)
    }

    /// ๐Ÿ”„ Load license from JSON string
    pub fn from_json(json_str: &str) -> Result<Self, serde_json::Error> {
        serde_json::from_str(json_str)
    }

    /// ๐Ÿ“ Display summary
    pub fn summary(&self) -> String {
        format!(
            "๐Ÿ“œ License: Use = {}, Royalty = {}%, Creator = {}{}{}",
            self.allowed_use,
            self.royalty_percent,
            self.creator,
            match &self.expires_on {
                Some(date) => format!(", Expires = {}", date),
                None => "".to_string(),
            },
            match &self.notes {
                Some(n) => format!(", Notes: {}", n),
                None => "".to_string(),
            }
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_license_serialization_roundtrip() {
        let license = VaultLicense::new("rio@vios.dev", "commercial", 15, Some("2026-12-31"), Some("Test license"));
        let json = license.to_json().unwrap();
        let parsed = VaultLicense::from_json(&json).unwrap();
        assert_eq!(license.creator, parsed.creator);
        assert_eq!(license.allowed_use, parsed.allowed_use);
    }
}