Skip to content

Commit c41bbb5

Browse files
committed
feat(rust/signed-doc): add subcommand to inspect cose sign from hex-encoded strings
1 parent b5b09a3 commit c41bbb5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,31 @@ enum Cli {
2020
/// Inspects COSE document
2121
Inspect {
2222
/// Path to the fully formed (should has at least one signature) COSE document
23-
cose_sign: PathBuf,
23+
cose_sign_path: PathBuf,
24+
},
25+
/// Inspect COSE document hex-formatted bytes
26+
InspectBytes {
27+
/// Hex-formatted COSE SIGN Bytes
28+
cose_sign_str: String,
2429
},
2530
}
2631

2732
impl Cli {
2833
/// Execute Cli command
2934
fn exec(self) -> anyhow::Result<()> {
30-
match self {
31-
Self::Inspect { cose_sign } => {
32-
//
33-
let mut cose_file = File::open(cose_sign)?;
35+
let cose_bytes = match self {
36+
Self::Inspect { cose_sign_path } => {
37+
let mut cose_file = File::open(cose_sign_path)?;
3438
let mut cose_file_bytes = Vec::new();
3539
cose_file.read_to_end(&mut cose_file_bytes)?;
36-
let cat_signed_doc: CatalystSignedDocument = cose_file_bytes.try_into()?;
37-
println!("{cat_signed_doc}");
38-
Ok(())
40+
cose_file_bytes
3941
},
40-
}
42+
Self::InspectBytes { cose_sign_str } => hex::decode(&cose_sign_str)?,
43+
};
44+
println!("Bytes read:\n{}\n", hex::encode(&cose_bytes));
45+
let cat_signed_doc: CatalystSignedDocument = cose_bytes.try_into()?;
46+
println!("{cat_signed_doc}");
47+
Ok(())
4148
}
4249
}
4350

0 commit comments

Comments
 (0)