@@ -103,4 +103,51 @@ impl Rules {
103103
104104 Ok ( res)
105105 }
106+
107+ /// Returns an iterator with all defined Catalyst Signed Documents validation rules
108+ /// per corresponding document type based on the `signed_doc.json` file
109+ ///
110+ /// # Errors:
111+ /// - `signed_doc.json` filed loading and JSON parsing errors.
112+ /// - `catalyst-signed-doc-spec` crate version doesn't align with the latest version
113+ /// of the `signed_doc.json`.
114+ pub ( crate ) fn documents_rules (
115+ ) -> anyhow:: Result < impl Iterator < Item = ( crate :: DocType , crate :: validator:: rules:: Rules ) > >
116+ {
117+ let spec = catalyst_signed_doc_spec:: CatalystSignedDocSpec :: load_signed_doc_spec ( ) ?;
118+
119+ let mut doc_rules = Vec :: new ( ) ;
120+ for ( _, doc_spec) in & spec. docs {
121+ let rules = Self {
122+ id : IdRule ,
123+ ver : VerRule ,
124+ content_type : ContentTypeRule :: new ( & doc_spec. headers . content_type ) ?,
125+ content_encoding : ContentEncodingRule :: NotSpecified ,
126+ template : TemplateRule :: NotSpecified ,
127+ parameters : ParametersRule :: NotSpecified ,
128+ doc_ref : RefRule :: new ( & spec. docs , & doc_spec. metadata . doc_ref ) ?,
129+ reply : ReplyRule :: NotSpecified ,
130+ section : SectionRule :: NotSpecified ,
131+ content : ContentRule :: Nil ,
132+ kid : SignatureKidRule { exp : & [ ] } ,
133+ signature : SignatureRule { mutlisig : false } ,
134+ original_author : OriginalAuthorRule ,
135+ } ;
136+ let doc_type = doc_spec. doc_type . parse ( ) ?;
137+
138+ doc_rules. push ( ( doc_type, rules) ) ;
139+ }
140+
141+ Ok ( doc_rules. into_iter ( ) )
142+ }
143+ }
144+
145+ #[ cfg( test) ]
146+ mod tests {
147+ use super :: * ;
148+
149+ #[ test]
150+ fn rules_documents_rules_test ( ) {
151+ let _unused = Rules :: documents_rules ( ) . unwrap ( ) ;
152+ }
106153}
0 commit comments