Skip to main content

cordance_cortex/
lib.rs

1//! Cortex adapter. Emits `cordance-cortex-receipt-v1-candidate` JSON only.
2//!
3//! ADR 0005: Cordance never writes to the cortex repo or runtime. It produces
4//! a receipt; the operator hands the receipt to Cortex via Cortex's own
5//! acceptance flow.
6
7#![forbid(unsafe_code)]
8#![deny(clippy::unwrap_used, clippy::expect_used)]
9
10use cordance_core::pack::CordancePack;
11use cordance_core::receipt::{AuthorityBoundary, CortexReceiptV1Candidate};
12
13pub mod builder;
14pub mod validator;
15
16#[derive(Debug, thiserror::Error)]
17pub enum CortexError {
18    #[error("receipt validation error: {0}")]
19    Validation(String),
20    #[error("serialisation error: {0}")]
21    Serde(#[from] serde_json::Error),
22}
23
24/// Build a candidate receipt from a compiled pack.
25///
26/// # Errors
27/// Returns `CortexError::Validation` if the assembled receipt fails structural
28/// validation.
29#[allow(clippy::missing_errors_doc)]
30pub fn build_receipt(pack: &CordancePack) -> Result<CortexReceiptV1Candidate, CortexError> {
31    builder::build_receipt(pack)
32}
33
34/// Quick check: a fresh `AuthorityBoundary::candidate_only()` is always safe.
35#[must_use]
36pub const fn safe_boundary() -> AuthorityBoundary {
37    AuthorityBoundary::candidate_only()
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn safe_boundary_grants_nothing() {
46        let b = safe_boundary();
47        assert!(b.candidate_only);
48        assert!(!b.cortex_truth_allowed);
49    }
50}