-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(rust/signed_doc): Impl Display for CatalystSignedDocument, add in…
…spect example
- Loading branch information
1 parent
f06b177
commit 96846f0
Showing
2 changed files
with
275 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Inspect a Catalyst Signed Document. | ||
use std::{ | ||
fs::{ | ||
// read_to_string, | ||
File, | ||
}, | ||
io::{ | ||
Read, | ||
// Write | ||
}, | ||
path::PathBuf, | ||
}; | ||
|
||
use clap::Parser; | ||
use signed_doc::CatalystSignedDocument; | ||
|
||
/// Hermes cli commands | ||
#[derive(clap::Parser)] | ||
enum Cli { | ||
/// Inspects COSE document | ||
Inspect { | ||
/// Path to the fully formed (should has at least one signature) COSE document | ||
cose_sign: PathBuf, | ||
/// Path to the json schema (Draft 7) to validate document against it | ||
doc_schema: PathBuf, | ||
}, | ||
} | ||
|
||
impl Cli { | ||
/// Execute Cli command | ||
fn exec(self) -> anyhow::Result<()> { | ||
match self { | ||
Self::Inspect { | ||
cose_sign, | ||
doc_schema: _, | ||
} => { | ||
// | ||
let mut cose_file = File::open(cose_sign)?; | ||
let mut cose_file_bytes = Vec::new(); | ||
cose_file.read_to_end(&mut cose_file_bytes)?; | ||
let cat_signed_doc: CatalystSignedDocument = cose_file_bytes.try_into()?; | ||
println!("{cat_signed_doc}"); | ||
Ok(()) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("Catalyst Signed Document"); | ||
if let Err(err) = Cli::parse().exec() { | ||
println!("{err}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters