• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / catalyst-libs / 20943573394

13 Jan 2026 03:28AM UTC coverage: 69.755% (+0.2%) from 69.556%
20943573394

Pull #773

github

web-flow
Merge 8e8b185b4 into 7c0be4d41
Pull Request #773: feat(catalyst-python): Initial setup of `catalyst-python` FFI Rust bindings

16112 of 23098 relevant lines covered (69.75%)

2648.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.53
/rust/signed_doc/src/validator/rules/mod.rs
1
//! A list of validation rules for all metadata fields
2
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/meta/>
3

4
use anyhow::Context;
5
use catalyst_signed_doc_spec::{DocSpec, DocSpecs, cddl_definitions::CddlDefinitions};
6

7
mod chain;
8
mod collaborators;
9
mod content;
10
mod content_encoding;
11
mod content_type;
12
mod doc_ref;
13
mod id;
14
mod ownership;
15
mod parameters;
16
mod reply;
17
mod revocations;
18
mod section;
19
mod signature;
20
mod signature_kid;
21
mod template;
22
mod utils;
23
mod ver;
24

25
pub(crate) use chain::ChainRule;
26
pub(crate) use collaborators::CollaboratorsRule;
27
pub(crate) use content::ContentRule;
28
pub(crate) use content_encoding::ContentEncodingRule;
29
pub(crate) use content_type::ContentTypeRule;
30
pub(crate) use doc_ref::RefRule;
31
pub(crate) use id::IdRule;
32
pub(crate) use ownership::DocumentOwnershipRule;
33
pub(crate) use parameters::ParametersRule;
34
pub(crate) use reply::ReplyRule;
35
pub(crate) use revocations::RevocationsRule;
36
pub(crate) use section::SectionRule;
37
pub(crate) use signature::SignatureRule;
38
pub(crate) use signature_kid::SignatureKidRule;
39
pub(crate) use template::TemplateRule;
40
pub(crate) use ver::VerRule;
41

42
use crate::validator::Rules;
43

44
/// Creating a rules instances from the provided specs.
45
fn rules_for_doc(
2,919✔
46
    cddl_defs: &CddlDefinitions,
2,919✔
47
    all_docs_specs: &DocSpecs,
2,919✔
48
    doc_spec: &DocSpec,
2,919✔
49
) -> anyhow::Result<Rules> {
2,919✔
50
    Ok(vec![
2,919✔
51
        Box::new(IdRule),
2,919✔
52
        Box::new(VerRule),
2,919✔
53
        Box::new(ContentTypeRule::new(&doc_spec.headers.content_type)?),
2,919✔
54
        Box::new(ContentEncodingRule::new(
2,919✔
55
            &doc_spec.headers.content_encoding,
2,919✔
56
        )?),
×
57
        Box::new(TemplateRule::new(
2,919✔
58
            all_docs_specs,
2,919✔
59
            &doc_spec.metadata.template,
2,919✔
60
        )?),
×
61
        Box::new(ParametersRule::new(
2,919✔
62
            all_docs_specs,
2,919✔
63
            &doc_spec.metadata.parameters,
2,919✔
64
        )?),
×
65
        Box::new(ChainRule::new(
2,919✔
66
            &doc_spec.metadata.chain,
2,919✔
67
            &doc_spec.metadata.collaborators,
2,919✔
68
        )?),
×
69
        Box::new(RefRule::new(all_docs_specs, &doc_spec.metadata.doc_ref)?),
2,919✔
70
        Box::new(ReplyRule::new(all_docs_specs, &doc_spec.metadata.reply)?),
2,919✔
71
        Box::new(RevocationsRule::new(&doc_spec.metadata.revocations)),
2,919✔
72
        Box::new(SectionRule::NotSpecified),
2,919✔
73
        Box::new(CollaboratorsRule::new(&doc_spec.metadata.collaborators)),
2,919✔
74
        Box::new(ContentRule::new(cddl_defs, &doc_spec.payload)?),
2,919✔
75
        Box::new(SignatureKidRule::new(&doc_spec.signers.roles)?),
2,919✔
76
        Box::new(SignatureRule),
2,919✔
77
        Box::new(DocumentOwnershipRule::new(
2,919✔
78
            &doc_spec.signers.update,
2,919✔
79
            doc_spec,
2,919✔
80
        )?),
×
81
    ])
82
}
2,919✔
83

84
/// Returns an iterator with all defined Catalyst Signed Documents validation rules
85
/// per corresponding document type based on the `signed_doc.json` file
86
///
87
/// # Errors:
88
///  - `signed_doc.json` filed loading and JSON parsing errors.
89
///  - `catalyst-signed-doc-spec` crate version doesn't  align with the latest version of
90
///    the `signed_doc.json`.
91
pub(crate) fn documents_rules_from_spec()
139✔
92
-> anyhow::Result<impl Iterator<Item = (crate::DocType, Rules)>> {
139✔
93
    let spec = catalyst_signed_doc_spec::CatalystSignedDocSpec::load_signed_doc_spec()?;
139✔
94

95
    let mut doc_rules = Vec::new();
139✔
96
    for (doc_name, doc_spec) in spec.docs.iter() {
3,197✔
97
        if doc_spec.draft {
3,197✔
98
            continue;
278✔
99
        }
2,919✔
100

101
        let rules = rules_for_doc(&spec.cddl_definitions, &spec.docs, doc_spec)
2,919✔
102
            .context(format!("Fail to initializing document '{doc_name}'"))?;
2,919✔
103
        let doc_type = doc_spec.doc_type.parse()?;
2,919✔
104

105
        doc_rules.push((doc_type, rules));
2,919✔
106
    }
107

108
    Ok(doc_rules.into_iter())
139✔
109
}
139✔
110

111
#[cfg(test)]
112
mod tests {
113
    use super::*;
114

115
    #[test]
116
    fn rules_documents_rules_test() {
1✔
117
        for (doc_type, rules) in documents_rules_from_spec()
21✔
118
            .map_err(|e| format!("{e:#}"))
1✔
119
            .unwrap()
1✔
120
        {
21✔
121
            println!("{doc_type}: {rules:?}");
21✔
122
        }
21✔
123
    }
1✔
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc