Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI tool #72

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ x509-cert = { version = "0.1.1", features = ["pem"] }

ssi-jwk = { version = "0.1" }
isomdl-macros = { version = "0.1.0", path = "macros" }
clap = { version = "4", features = ["derive"] }
clap-stdin = "0.2.1"

[dependencies.cose-rs]
git = "https://github.com/spruceid/cose-rs"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# isomdl

ISO mDL implementation in Rust

## CLI tool

This crate contains a CLI tool. Run the `--help` command to see what actions you can perform.

```bash
cargo run -- --help
```

For example you can get the namespaces and elements defined in an mDL:
```bash
cat test/stringified-mdl.txt | cargo run -- get-namespaces -
```
48 changes: 48 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::BTreeMap;

use anyhow::{Context, Error};
use clap::Parser;
use clap_stdin::MaybeStdin;
use isomdl::presentation::{device::Document, Stringify};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[command(subcommand)]
action: Action,
}

#[derive(Debug, clap::Subcommand)]
enum Action {
/// Print the namespaces and element identifiers used in an mDL.
GetNamespaces {
/// Base64 encoded mDL in the format used in the issuance module of this crate.
mdl: MaybeStdin<String>,
},
}

fn main() -> Result<(), Error> {
match Args::parse().action {
Action::GetNamespaces { mdl } => print_namespaces(mdl.to_string()),
}
}

fn print_namespaces(mdl: String) -> Result<(), Error> {
let claims = Document::parse(mdl)
.context("could not parse mdl")?
.namespaces
.into_inner()
.into_iter()
.map(|(ns, inner)| (ns, inner.into_inner().into_keys().collect()))
.collect::<BTreeMap<String, Vec<String>>>();
println!("{}", serde_json::to_string_pretty(&claims)?);
Ok(())
}

#[cfg(test)]
mod test {
#[test]
fn print_namespaces() {
super::print_namespaces(include_str!("../test/stringified-mdl.txt").to_string()).unwrap()
}
}
1 change: 1 addition & 0 deletions test/stringified-mdl.txt

Large diffs are not rendered by default.

Loading