use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use uuid::Uuid; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SnapshotManifest { pub snapshot_id: Uuid, pub orbit_id: Uuid, pub orbit_name: String, pub labels: Vec, pub provider: String, pub paths: Vec, pub restore_hints: serde_json::Value, } pub fn manifest_hash(manifest: &SnapshotManifest) -> String { let json = serde_json::to_vec(manifest).expect("manifest serializes"); let digest = Sha256::digest(&json); hex::encode(digest) } #[cfg(test)] mod tests { use super::*; #[test] fn hash_is_stable() { let m = SnapshotManifest { snapshot_id: Uuid::nil(), orbit_id: Uuid::nil(), orbit_name: "nightly".into(), labels: vec!["filesystem".into()], provider: "filesystem".into(), paths: vec!["/tmp".into()], restore_hints: serde_json::json!({}), }; let h1 = manifest_hash(&m); let h2 = manifest_hash(&m); assert_eq!(h1, h2); assert_eq!(h1.len(), 64); } }