chore: reorg code
This commit is contained in:
@@ -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);
|
||||
@@ -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() {
|
||||
@@ -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::<u32>() {
|
||||
Ok(t) => (t * 1000) as u64,
|
||||
@@ -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"))
|
||||
40
src/main.rs
40
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<Box<dyn Command>> = 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"))
|
||||
|
||||
Reference in New Issue
Block a user