File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
rust/signed_doc/src/validator/rules Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 22
33use std:: fmt:: Debug ;
44
5+ use catalyst_signed_doc_spec:: payload:: Payload ;
56use minicbor:: Encode ;
67
78use crate :: {
@@ -39,6 +40,26 @@ pub(crate) enum ContentRule {
3940}
4041
4142impl ContentRule {
43+ /// Generating `ContentRule` from specs
44+ pub ( crate ) fn new ( spec : & Payload ) -> anyhow:: Result < Self > {
45+ if spec. nil {
46+ anyhow:: ensure!(
47+ spec. schema. is_none( ) ,
48+ "'schema' field could not been specified when 'nil' is 'true' for 'payload' definition"
49+ ) ;
50+ return Ok ( Self :: Nil ) ;
51+ }
52+
53+ if let Some ( schema) = & spec. schema {
54+ let schema_str = schema. to_string ( ) ;
55+ Ok ( Self :: StaticSchema ( ContentSchema :: Json (
56+ json_schema:: JsonSchema :: try_from ( & serde_json:: from_str ( & schema_str) ?) ?,
57+ ) ) )
58+ } else {
59+ Ok ( Self :: NotNil )
60+ }
61+ }
62+
4263 /// Field validation rule
4364 #[ allow( clippy:: unused_async) ]
4465 pub ( crate ) async fn check (
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ impl Rules {
132132 doc_ref : RefRule :: new ( & spec. docs , & doc_spec. metadata . doc_ref ) ?,
133133 reply : ReplyRule :: NotSpecified ,
134134 section : SectionRule :: NotSpecified ,
135- content : ContentRule :: Nil ,
135+ content : ContentRule :: new ( & doc_spec . payload ) ? ,
136136 kid : SignatureKidRule { exp : & [ ] } ,
137137 signature : SignatureRule { mutlisig : false } ,
138138 original_author : OriginalAuthorRule ,
You can’t perform that action at this time.
0 commit comments