diff --git a/src/chall.rs b/src/cmd_chall.rs similarity index 100% rename from src/chall.rs rename to src/cmd_chall.rs diff --git a/src/challconfig.rs b/src/cmd_challconfig.rs similarity index 100% rename from src/challconfig.rs rename to src/cmd_challconfig.rs diff --git a/src/pgp.rs b/src/cmd_pgp.rs similarity index 97% rename from src/pgp.rs rename to src/cmd_pgp.rs index 89de3ff..1c90d55 100644 --- a/src/pgp.rs +++ b/src/cmd_pgp.rs @@ -17,8 +17,8 @@ impl Command for CommandImpl { fn name(&self) -> &str { "pgp" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand") - .arg(Arg::with_name("in").short("i").long("in").takes_value(true).help("File input")) + SubCommand::with_name(self.name()).about("OpenPGP subcommand") + .arg(Arg::with_name("in").short("i").long("in").takes_value(true).help("File input, *.pgp or *.asc")) .arg(Arg::with_name("detail").long("detail").help("Detail output")) .arg(Arg::with_name("json").long("json").help("JSON output")) } @@ -27,10 +27,7 @@ impl Command for CommandImpl { let in_file = sub_arg_matches.value_of("in"); let show_detail = sub_arg_matches.is_present("detail"); - let in_file = match in_file { - Some(i) => i, - None => return simple_error!("Input file must assined"), - }; + let in_file = opt_value_result!(in_file, "Input file must assined"); let in_file_bytes = opt_result!(std::fs::read(in_file), "Read file: {}, failed: {}", in_file); let p = PacketParser::from_bytes(&in_file_bytes); diff --git a/src/pgpcarddecrypt.rs b/src/cmd_pgpcarddecrypt.rs similarity index 100% rename from src/pgpcarddecrypt.rs rename to src/cmd_pgpcarddecrypt.rs diff --git a/src/pgpcardlist.rs b/src/cmd_pgpcardlist.rs similarity index 98% rename from src/pgpcardlist.rs rename to src/cmd_pgpcardlist.rs index 91a9afc..c263f74 100644 --- a/src/pgpcardlist.rs +++ b/src/cmd_pgpcardlist.rs @@ -15,9 +15,7 @@ impl Command for CommandImpl { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let json_output = sub_arg_matches.is_present("json"); - if json_output { - rust_util::util_msg::set_logger_std_out(false); - } + if json_output { rust_util::util_msg::set_logger_std_out(false); } let mut json = BTreeMap::new(); match OpenPGPCard::list_cards() { diff --git a/src/pgpcardsign.rs b/src/cmd_pgpcardsign.rs similarity index 100% rename from src/pgpcardsign.rs rename to src/cmd_pgpcardsign.rs diff --git a/src/piv.rs b/src/cmd_piv.rs similarity index 100% rename from src/piv.rs rename to src/cmd_piv.rs diff --git a/src/pivsign.rs b/src/cmd_pivsign.rs similarity index 100% rename from src/pivsign.rs rename to src/cmd_pivsign.rs diff --git a/src/register.rs b/src/cmd_register.rs similarity index 95% rename from src/register.rs rename to src/cmd_register.rs index 2224267..277d043 100644 --- a/src/register.rs +++ b/src/cmd_register.rs @@ -11,10 +11,10 @@ use crate::fido::{U2fV2Challenge, U2fRegistrationData}; pub struct CommandImpl; impl Command for CommandImpl { - fn name(&self) -> &str { "register" } + fn name(&self) -> &str { "u2f-register" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("Register subcommand") + SubCommand::with_name(self.name()).about("FIDO U2F Register subcommand") .arg(Arg::with_name("app-id").short("a").long("app-id").default_value("https://example.com").help("App id")) .arg(Arg::with_name("timeout").short("t").long("timeout").default_value("10").help("Timeout in seconds")) .arg(Arg::with_name("json").long("json").help("JSON output")) @@ -22,9 +22,8 @@ impl Command for CommandImpl { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let json_output = sub_arg_matches.is_present("json"); - if json_output { - rust_util::util_msg::set_logger_std_out(false); - } + if json_output { rust_util::util_msg::set_logger_std_out(false); } + let app_id = sub_arg_matches.value_of("app-id").unwrap(); let timeout_ms = match sub_arg_matches.value_of("timeout").unwrap().parse::() { Ok(t) => (t * 1000) as u64, diff --git a/src/sign.rs b/src/cmd_sign.rs similarity index 96% rename from src/sign.rs rename to src/cmd_sign.rs index a25c313..f4f0448 100644 --- a/src/sign.rs +++ b/src/cmd_sign.rs @@ -11,9 +11,9 @@ use crate::fido::U2fV2Challenge; pub struct CommandImpl; impl Command for CommandImpl { - fn name(&self) -> &str { "sign" } + fn name(&self) -> &str { "u2f-sign" } fn subcommand<'a>(&self) -> App<'a, 'a> { - SubCommand::with_name(self.name()).about("Sign subcommand") + SubCommand::with_name(self.name()).about("FIDO U2F Sign subcommand") .arg(Arg::with_name("app-id").short("a").long("app-id").default_value("https://example.com").help("App id")) .arg(Arg::with_name("timeout").short("t").long("timeout").default_value("10").help("Timeout in seconds")) .arg(Arg::with_name("key-handle").short("k").long("key-handle").takes_value(true).multiple(true).help("Key handle")) diff --git a/src/main.rs b/src/main.rs index 361635f..90ed221 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,17 +3,17 @@ extern crate rust_util; mod fido; mod digest; -mod register; -mod sign; -mod pgp; +mod cmd_register; +mod cmd_sign; +mod cmd_pgp; mod pgpcardutil; -mod pgpcardlist; -mod pgpcardsign; -mod pgpcarddecrypt; -mod piv; -mod pivsign; -mod chall; -mod challconfig; +mod cmd_pgpcardlist; +mod cmd_pgpcardsign; +mod cmd_pgpcarddecrypt; +mod cmd_piv; +mod cmd_pivsign; +mod cmd_chall; +mod cmd_challconfig; use clap::{App, AppSettings, ArgMatches}; use rust_util::util_clap::{CommandError, Command}; @@ -38,16 +38,16 @@ fn main() { fn inner_main() -> CommandError { let commands: Vec> = vec![ - Box::new(register::CommandImpl), - Box::new(sign::CommandImpl), - Box::new(pgp::CommandImpl), - Box::new(pgpcardlist::CommandImpl), - Box::new(pgpcardsign::CommandImpl), - Box::new(pgpcarddecrypt::CommandImpl), - Box::new(piv::CommandImpl), - Box::new(pivsign::CommandImpl), - Box::new(chall::CommandImpl), - Box::new(challconfig::CommandImpl), + Box::new(cmd_register::CommandImpl), + Box::new(cmd_sign::CommandImpl), + Box::new(cmd_pgp::CommandImpl), + Box::new(cmd_pgpcardlist::CommandImpl), + Box::new(cmd_pgpcardsign::CommandImpl), + Box::new(cmd_pgpcarddecrypt::CommandImpl), + Box::new(cmd_piv::CommandImpl), + Box::new(cmd_pivsign::CommandImpl), + Box::new(cmd_chall::CommandImpl), + Box::new(cmd_challconfig::CommandImpl), ]; let mut app = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION"))