Skip to content

Commit b0aa90a

Browse files
committed
fix(rust/signed_doc): cleanup and fix to DocumentRef serde
1 parent 478f5ab commit b0aa90a

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

rust/signed_doc/examples/cat-signed-doc.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ enum Cli {
2121
Inspect {
2222
/// Path to the fully formed (should has at least one signature) COSE document
2323
cose_sign: PathBuf,
24-
/// Path to the json schema (Draft 7) to validate document against it
25-
doc_schema: PathBuf,
2624
},
2725
}
2826

2927
impl Cli {
3028
/// Execute Cli command
3129
fn exec(self) -> anyhow::Result<()> {
3230
match self {
33-
Self::Inspect {
34-
cose_sign,
35-
doc_schema: _,
36-
} => {
31+
Self::Inspect { cose_sign } => {
3732
//
3833
let mut cose_file = File::open(cose_sign)?;
3934
let mut cose_file_bytes = Vec::new();
@@ -48,6 +43,7 @@ impl Cli {
4843

4944
fn main() {
5045
println!("Catalyst Signed Document");
46+
println!("------------------------");
5147
if let Err(err) = Cli::parse().exec() {
5248
println!("{err}");
5349
}

rust/signed_doc/examples/mk_signed_doc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn decode_cbor_uuid(val: &coset::cbor::Value) -> anyhow::Result<uuid::Uuid> {
8484
fn encode_cbor_document_ref(doc_ref: &DocumentRef) -> coset::cbor::Value {
8585
match doc_ref {
8686
DocumentRef::Latest { id } => encode_cbor_uuid(id),
87-
DocumentRef::WithVer { id, ver } => {
87+
DocumentRef::WithVer(id, ver) => {
8888
coset::cbor::Value::Array(vec![encode_cbor_uuid(id), encode_cbor_uuid(ver)])
8989
},
9090
}
@@ -101,7 +101,7 @@ fn decode_cbor_document_ref(val: &coset::cbor::Value) -> anyhow::Result<Document
101101
anyhow::ensure!(array.len() == 2, "Invalid CBOR encoded document `ref` type");
102102
let id = decode_cbor_uuid(&array[0])?;
103103
let ver = decode_cbor_uuid(&array[1])?;
104-
Ok(DocumentRef::WithVer { id, ver })
104+
Ok(DocumentRef::WithVer(id, ver))
105105
}
106106
}
107107

@@ -133,6 +133,7 @@ impl Cli {
133133
let schema = load_schema_from_file(&schema)?;
134134
let cose = load_cose_from_file(&doc)?;
135135
validate_cose(&cose, &pk, &schema)?;
136+
println!("Document is valid.");
136137
},
137138
}
138139
println!("Done");

rust/signed_doc/meta.schema.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@
4141
}
4242
},
4343
{
44-
"type": "object",
45-
"properties": {
46-
"id": {
47-
"$ref": "#/definitions/uuidv7"
48-
},
49-
"ver": {
50-
"$ref": "#/definitions/uuidv7"
51-
}
52-
}
44+
"type": "array",
45+
"items": {
46+
"$ref": "#/definitions/uuidv7"
47+
},
48+
"minItems": 2
5349
}
5450
]
5551
},

rust/signed_doc/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ pub struct CatalystSignedDocument {
3030
impl Display for CatalystSignedDocument {
3131
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
3232
writeln!(f, "{}", self.inner.metadata)?;
33-
writeln!(f, "JSON Payload {:#}", self.inner.payload)?;
33+
writeln!(f, "JSON Payload {:#}\n", self.inner.payload)?;
3434
writeln!(f, "Signatures [")?;
3535
for signature in &self.inner.signatures {
36-
writeln!(f, " {:#}", hex::encode(signature.signature.as_slice()))?;
36+
writeln!(f, " 0x{:#}", hex::encode(signature.signature.as_slice()))?;
3737
}
38-
writeln!(f, "]")?;
38+
writeln!(f, "]\n")?;
3939
writeln!(f, "Content Errors [")?;
4040
for error in &self.inner.content_errors {
4141
writeln!(f, " {error:#}")?;
@@ -116,12 +116,8 @@ pub enum DocumentRef {
116116
id: uuid::Uuid,
117117
},
118118
/// Reference to the specific document version
119-
WithVer {
120-
/// Document ID UUID
121-
id: uuid::Uuid,
122-
/// Document Version UUID
123-
ver: uuid::Uuid,
124-
},
119+
/// Document ID UUID, Document Ver UUID
120+
WithVer(uuid::Uuid, uuid::Uuid),
125121
}
126122

127123
// Do this instead of `new` if we are converting a single parameter into a struct/type we
@@ -249,7 +245,7 @@ fn decode_cbor_document_ref(val: &coset::cbor::Value) -> anyhow::Result<Document
249245
anyhow::ensure!(array.len() == 2, "Invalid CBOR encoded document `ref` type");
250246
let id = decode_cbor_uuid(&array[0])?;
251247
let ver = decode_cbor_uuid(&array[1])?;
252-
Ok(DocumentRef::WithVer { id, ver })
248+
Ok(DocumentRef::WithVer(id, ver))
253249
}
254250
}
255251

0 commit comments

Comments
 (0)