argone-signing 0.1.1

Sign Argone packages and verify their trust chain (Ed25519 + BLAKE3).
Documentation
use crate::SigError;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Release {
    pub format_version: u32,
    pub name: String,
    pub version: String,
    pub kind: manifest::Kind,
    pub critical: bool,
    pub channel: String,
    pub publisher_id: String,
    pub published_at: String,
}

impl Release {
    pub fn to_json_bytes(&self) -> Result<Vec<u8>, SigError> {
        serde_json::to_vec(self).map_err(|e| SigError::Json(e.to_string()))
    }
    pub fn from_json_str(s: &str) -> Result<Release, SigError> {
        let r: Release = serde_json::from_str(s).map_err(|e| SigError::Json(e.to_string()))?;
        if r.format_version != crate::FORMAT_VERSION {
            return Err(SigError::FormatIncompatible {
                found: r.format_version,
            });
        }
        Ok(r)
    }
}

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

    fn sample() -> Release {
        Release {
            format_version: crate::FORMAT_VERSION,
            name: "shell".into(),
            version: "0.2.0".into(),
            kind: manifest::Kind::Application,
            critical: false,
            channel: "stable".into(),
            publisher_id: "dev".into(),
            published_at: "2026-07-12T00:00:00Z".into(),
        }
    }

    #[test]
    fn release_json_round_trips() {
        let r = sample();
        let bytes = r.to_json_bytes().unwrap();
        let back = Release::from_json_str(std::str::from_utf8(&bytes).unwrap()).unwrap();
        assert_eq!(r, back);
    }

    #[test]
    fn release_rejects_unknown_field() {
        // A stray key (e.g. a tampered `critical` smuggled elsewhere) must be rejected.
        let bad = r#"{"format_version":1,"name":"x","version":"1.0.0","kind":"application",
            "critical":false,"channel":"stable","publisher_id":"dev",
            "published_at":"t","rogue":1}"#;
        assert!(Release::from_json_str(bad).is_err());
    }

    #[test]
    fn digest_is_stable_and_order_sensitive() {
        assert_eq!(
            crate::digest(b"a", b"b", b"c"),
            crate::digest(b"a", b"b", b"c")
        );
        assert_ne!(
            crate::digest(b"a", b"b", b"c"),
            crate::digest(b"b", b"a", b"c")
        );
    }
}