use proof_core::{ErrorCode, LifecycleStatus};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Validity {
Valid,
Invalid,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PolicyDecision {
Pass,
Fail,
Indeterminate,
}
impl PolicyDecision {
pub fn as_str(self) -> &'static str {
match self {
Self::Pass => "pass",
Self::Fail => "fail",
Self::Indeterminate => "indeterminate",
}
}
}
#[derive(Debug, Clone)]
pub struct CheckRecord {
pub stage: &'static str,
pub object: String,
pub ok: bool,
pub code: Option<ErrorCode>,
pub message: String,
}
impl CheckRecord {
pub fn ok(stage: &'static str, object: impl Into<String>, message: impl Into<String>) -> Self {
Self {
stage,
object: object.into(),
ok: true,
code: None,
message: message.into(),
}
}
pub fn fail(
stage: &'static str,
object: impl Into<String>,
code: ErrorCode,
message: impl Into<String>,
) -> Self {
Self {
stage,
object: object.into(),
ok: false,
code: Some(code),
message: message.into(),
}
}
pub fn note(
stage: &'static str,
object: impl Into<String>,
message: impl Into<String>,
) -> Self {
Self {
stage,
object: object.into(),
ok: true,
code: None,
message: message.into(),
}
}
}
#[derive(Debug, Clone)]
pub struct LifecycleRecord {
pub object: String,
pub status: LifecycleStatus,
pub code: Option<ErrorCode>,
pub message: String,
}
#[derive(Debug, Clone)]
pub struct VerifyReport {
pub proof_id: Option<String>,
pub cryptographic_validity: Validity,
pub evidence_validity: Validity,
pub policy_decision: PolicyDecision,
pub lifecycle_checked: bool,
pub lifecycle: Vec<LifecycleRecord>,
pub status_objects: Vec<String>,
pub checks: Vec<CheckRecord>,
}
impl VerifyReport {
pub fn failure_codes(&self) -> Vec<ErrorCode> {
self.checks
.iter()
.filter(|c| !c.ok)
.filter_map(|c| c.code)
.collect()
}
pub fn passed_crypto(&self) -> bool {
self.cryptographic_validity == Validity::Valid
}
}