use serde::{Deserialize, Serialize};
use crate::error::{TrustError, TrustResult};
pub const INCLUSION_PROOF_FORMAT: &str = "lys/log-inclusion-proof/v1";
pub const CONSISTENCY_PROOF_FORMAT: &str = "lys/log-consistency-proof/v1";
pub const MAX_JSON_TREE_SIZE: u64 = 1 << 53;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct InclusionProofArtifact {
pub format: String,
pub tree_size: u64,
pub leaf_index: u64,
pub hashes: Vec<String>,
pub checkpoint: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConsistencyProofArtifact {
pub format: String,
pub tree_size_1: u64,
pub tree_size_2: u64,
pub hashes: Vec<String>,
pub checkpoint_1: String,
pub checkpoint_2: String,
}
pub(crate) fn check_json_safe_tree_size(tree_size: u64) -> TrustResult<()> {
if tree_size >= MAX_JSON_TREE_SIZE {
return Err(TrustError::LogArtifactEncoding {
reason: format!(
"tree size {tree_size} is at or beyond the JSON-safe bound 2^53 \
({MAX_JSON_TREE_SIZE})"
),
});
}
Ok(())
}
#[cfg(test)]
#[path = "artifact_tests.rs"]
mod tests;