Skip to content

Commit f57335e

Browse files
committed
add a new variant for schema, Cddl
1 parent 041a66d commit f57335e

File tree

2 files changed

+21
-9
lines changed
  • rust
    • catalyst-signed-doc-spec/src
    • signed_doc/src/validator/rules/content

2 files changed

+21
-9
lines changed

rust/catalyst-signed-doc-spec/src/payload.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@
55
#[allow(clippy::missing_docs_in_private_items)]
66
pub struct Payload {
77
pub nil: bool,
8-
pub schema: Option<serde_json::Value>,
8+
pub schema: Option<Schema>,
9+
}
10+
11+
#[derive(serde::Deserialize)]
12+
#[serde(untagged)]
13+
pub enum Schema {
14+
JsonSchema(serde_json::Value),
15+
Cddl(String),
916
}

rust/signed_doc/src/validator/rules/content/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod tests;
55

66
use std::fmt::Debug;
77

8-
use catalyst_signed_doc_spec::payload::Payload;
8+
use catalyst_signed_doc_spec::payload::{Payload, Schema};
99
use minicbor::Encode;
1010

1111
use crate::{
@@ -18,6 +18,8 @@ use crate::{
1818
pub(crate) enum ContentSchema {
1919
/// Draft 7 JSON schema
2020
Json(json_schema::JsonSchema),
21+
/// CDDL schema
22+
Cddl,
2123
}
2224

2325
impl Debug for ContentSchema {
@@ -27,6 +29,7 @@ impl Debug for ContentSchema {
2729
) -> std::fmt::Result {
2830
match self {
2931
Self::Json(_) => writeln!(f, "JsonSchema"),
32+
Self::Cddl => writeln!(f, "CddlSchema"),
3033
}
3134
}
3235
}
@@ -53,13 +56,14 @@ impl ContentRule {
5356
return Ok(Self::Nil);
5457
}
5558

56-
if let Some(schema) = &spec.schema {
57-
let schema_str = schema.to_string();
58-
Ok(Self::StaticSchema(ContentSchema::Json(
59-
json_schema::JsonSchema::try_from(&serde_json::from_str(&schema_str)?)?,
60-
)))
61-
} else {
62-
Ok(Self::NotNil)
59+
match &spec.schema {
60+
Some(Schema::JsonSchema(schema)) => {
61+
Ok(Self::StaticSchema(ContentSchema::Json(
62+
json_schema::JsonSchema::try_from(schema)?,
63+
)))
64+
},
65+
Some(Schema::Cddl(_)) => Ok(Self::StaticSchema(ContentSchema::Cddl)),
66+
None => Ok(Self::NotNil),
6367
}
6468
}
6569

@@ -75,6 +79,7 @@ impl ContentRule {
7579
ContentSchema::Json(json_schema) => {
7680
return Ok(content_json_schema_check(doc, json_schema))
7781
},
82+
ContentSchema::Cddl => return Ok(true),
7883
}
7984
}
8085
if let Self::NotNil = self {

0 commit comments

Comments
 (0)