diff --git a/src/cmd_pgpcardadmin.rs b/src/cmd_pgpcardadmin.rs index cda50f6..b762d24 100644 --- a/src/cmd_pgpcardadmin.rs +++ b/src/cmd_pgpcardadmin.rs @@ -1,6 +1,6 @@ use clap::{App, Arg, ArgMatches, SubCommand}; -use openpgp_card::{OpenPgp}; use openpgp_card::card_do::{Lang, Sex}; +use openpgp_card::OpenPgp; use rust_util::util_clap::{Command, CommandError}; pub struct CommandImpl; @@ -16,6 +16,7 @@ impl Command for CommandImpl { .arg(Arg::with_name("url").long("url").takes_value(true).required(false).help("Set URL")) .arg(Arg::with_name("lang").long("lang").takes_value(true).required(false).help("Set lang")) .arg(Arg::with_name("sex").long("sex").takes_value(true).required(false).help("Set sex, f or m")) + .arg(Arg::with_name("reset").long("reset").help("Reset card")) } fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { @@ -27,6 +28,13 @@ impl Command for CommandImpl { let mut pgp = OpenPgp::new(&mut card); let mut trans = opt_result!(pgp.transaction(), "Open card failed: {}"); + if sub_arg_matches.is_present("reset") { + warning!("Start reset card..."); + opt_result!(trans.factory_reset(), "Reset failed: {}"); + success!("Reset success"); + return Ok(None); + } + opt_result!(trans.verify_pw3(pin.as_ref()), "Admin pin verify failed: {}"); success!("Admin pin verify success!"); @@ -66,8 +74,6 @@ impl Command for CommandImpl { } } - // TODO Upload Key! - Ok(None) } } diff --git a/src/cmd_pgpcardmake.rs b/src/cmd_pgpcardmake.rs index c52dbf6..c4d82f6 100644 --- a/src/cmd_pgpcardmake.rs +++ b/src/cmd_pgpcardmake.rs @@ -135,7 +135,6 @@ impl Command for CommandImpl { } fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { - warning!("WORKING!!!"); let pin_opt = sub_arg_matches.value_of("pin"); let pin = opt_value_result!(pin_opt, "Pin must be assigned"); if pin.len() < 8 { return simple_error!("Admin pin length:{}, must >= 8!", pin.len()); } @@ -195,7 +194,7 @@ impl Command for CommandImpl { let force_make = sub_arg_matches.is_present("force-make"); if !force_make { - warning!("Force make is OFF, skip write private keys to card!"); + warning!("Force make is OFF, add argument --force-make to open, skip write private keys to card!"); return Ok(None); }