Skip to main content

kagi_sync/domain/
manifest.rs

1use serde::{Deserialize, Serialize};
2use sha2::{Digest, Sha256};
3
4#[derive(Serialize, Deserialize, Debug, Clone)]
5#[allow(dead_code)]
6pub struct ProjectStateManifest {
7    pub version: i64,
8    pub project_id: String,
9    pub revision: i64,
10    pub previous_manifest_hash: Option<String>,
11    pub kagi_json_hash: String,
12    pub access_json_hash: String,
13    pub file_hashes: Vec<FileHash>,
14    pub timestamp: String,
15    pub signer_member_id: String,
16    pub signer_public_key: String,
17}
18
19#[derive(Serialize, Deserialize, Debug, Clone)]
20#[allow(dead_code)]
21pub struct FileHash {
22    pub path: String,
23    pub sha256: String,
24}
25
26impl ProjectStateManifest {
27    #[allow(dead_code)]
28    pub fn compute_hash(&self) -> String {
29        let canonical = serde_json::to_string(self).unwrap_or_default();
30        let mut hasher = Sha256::new();
31        hasher.update(canonical.as_bytes());
32        hex::encode(hasher.finalize())
33    }
34}
35
36#[allow(dead_code)]
37pub fn hash_json(json: &str) -> String {
38    let mut hasher = Sha256::new();
39    hasher.update(json.as_bytes());
40    hex::encode(hasher.finalize())
41}