chore: use_clap & clippy

This commit is contained in:
2021-07-18 12:08:59 +08:00
parent bcf097292f
commit d44df83c7f
13 changed files with 49 additions and 49 deletions

View File

@@ -1,8 +1,8 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use yubico_manager::Yubico;
use yubico_manager::config::{Config, Mode, Slot};
use std::ops::Deref;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -55,6 +55,6 @@ impl Command for CommandImpl {
warning!("Yubikey not found");
}
Ok(())
Ok(None)
}
}

View File

@@ -1,9 +1,9 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use yubico_manager::Yubico;
use yubico_manager::config::Config;
use yubico_manager::hmacmode::HmacKey;
use yubico_manager::configure::DeviceModeConfig;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -58,6 +58,6 @@ impl Command for CommandImpl {
warning!("Yubikey not found");
}
Ok(())
Ok(None)
}
}

View File

@@ -1,24 +0,0 @@
use clap::{ArgMatches, App};
use rust_util::XResult;
pub type CommandError = XResult<()>;
pub trait Command {
fn name(&self) -> &str;
fn subcommand<'a>(&self) -> App<'a, 'a>;
fn run(&self, arg_matches: &ArgMatches, _: &ArgMatches) -> CommandError;
}
pub struct DefaultCommandImpl;
impl DefaultCommandImpl {
pub fn process_command<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
// app.arg(Arg::with_name("verbose").long("verbose").short("v").multiple(true).help("Show verbose info"))
}
pub fn run(_arg_matches: &ArgMatches) -> CommandError {
information!("WebAuthn(OpenPGP) cli, use --help for help");
Ok(())
}
}

View File

@@ -1,7 +1,7 @@
#[macro_use]
extern crate rust_util;
mod cmd;
// mod cmd;
mod fido;
mod digest;
mod register;
@@ -15,10 +15,20 @@ mod piv;
mod chall;
mod challconfig;
use clap::{App, AppSettings};
use cmd::{Command, CommandError};
use cmd::DefaultCommandImpl;
use clap::{App, AppSettings, ArgMatches};
use rust_util::util_clap::{CommandError, Command};
pub struct DefaultCommandImpl;
impl DefaultCommandImpl {
pub fn process_command<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
}
pub fn run(_arg_matches: &ArgMatches) -> CommandError {
information!("WebAuthn(OpenPGP) cli, use --help for help");
Ok(None)
}
}
fn main() {
if let Err(e) = inner_main() {

View File

@@ -1,5 +1,4 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use sequoia_openpgp::parse::Parse;
use sequoia_openpgp::parse::{PacketParser, PacketParserResult};
use sequoia_openpgp::Packet;
@@ -10,6 +9,7 @@ use sequoia_openpgp::crypto::mpi::PublicKey;
use openssl::bn::BigNum;
use pem::Pem;
use sequoia_openpgp::packet::signature::subpacket::SubpacketTag;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -162,7 +162,7 @@ impl Command for CommandImpl {
information!("FILE IS OTHER");
}
}
Ok(())
Ok(None)
}
}

View File

@@ -1,7 +1,7 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use openpgp_card::DecryptMe;
use std::collections::BTreeMap;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -56,6 +56,6 @@ impl Command for CommandImpl {
println!("{}", serde_json::to_string_pretty(&json).unwrap());
}
Ok(())
Ok(None)
}
}

View File

@@ -1,7 +1,7 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use openpgp_card::{OpenPGPCard, DecryptMe, Hash, KeyType};
use std::collections::BTreeMap;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -108,6 +108,6 @@ impl Command for CommandImpl {
}
}
}
Ok(())
Ok(None)
}
}

View File

@@ -1,8 +1,8 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use openpgp_card::Hash;
use rust_util::XResult;
use std::collections::BTreeMap;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -84,7 +84,7 @@ impl Command for CommandImpl {
println!("{}", serde_json::to_string_pretty(&json).unwrap());
}
Ok(())
Ok(None)
}
}

View File

@@ -1,5 +1,5 @@
use std::time::Duration;
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use yubikey::{YubiKey, Certificate};
use yubikey::piv::SlotId;
use rust_util::XResult;
@@ -8,6 +8,8 @@ use x509_parser::parse_x509_certificate;
use pem::Pem;
use digest::Digest;
use rust_util::util_msg::MessageType;
use chrono::Local;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -18,7 +20,7 @@ impl Command for CommandImpl {
SubCommand::with_name(self.name()).about("PIV subcommand")
.arg(Arg::with_name("detail").long("detail").help("Detail output"))
.arg(Arg::with_name("show-config").long("show-config").help("Show config output"))
// .arg(Arg::with_name("json").long("json").help("JSON output"))
// .arg(Arg::with_name("json").long("json").help("JSON output"))
}
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
@@ -47,7 +49,7 @@ impl Command for CommandImpl {
for slot in yubikey::piv::SLOTS.iter().cloned() {
print_cert_info(&mut yk, slot, detail_output).ok();
}
Ok(())
Ok(None)
}
}
@@ -89,7 +91,18 @@ fn print_cert_info(yubikey: &mut YubiKey, slot: SlotId, detail_output: bool) ->
success!("Issuer: {}", cert.tbs_certificate.issuer);
success!("Fingerprint(SHA256): {}", hex::encode(fingerprint_sha256));
success!("Not Before: {}", cert.tbs_certificate.validity.not_before.to_rfc2822());
success!("Not After: {}", cert.tbs_certificate.validity.not_after.to_rfc2822());
let mut not_after_desc = String::new();
let not_after_timestamp = cert.tbs_certificate.validity.not_after.timestamp();
let now_timestamp = Local::now().timestamp();
if not_after_timestamp < now_timestamp {
let expired_time = simpledateformat::format_human(Duration::from_secs((now_timestamp - not_after_timestamp) as u64));
not_after_desc.push_str(&format!("(EXPIRED {})", expired_time));
} else {
let valid_time = simpledateformat::format_human(Duration::from_secs((not_after_timestamp - now_timestamp) as u64));
not_after_desc.push_str(&format!("(left {})", valid_time));
}
success!("Not After: {} {}", cert.tbs_certificate.validity.not_after.to_rfc2822(), not_after_desc);
}
_ => {
warning!("Failed to parse certificate");

View File

@@ -1,5 +1,4 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use authenticator::authenticatorservice::AuthenticatorService;
use authenticator::statecallback::StateCallback;
use authenticator::RegisterFlags;
@@ -7,6 +6,7 @@ use std::sync::mpsc::channel;
use crate::fido;
use crate::digest;
use crate::fido::{U2fV2Challenge, U2fRegistrationData};
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -85,7 +85,7 @@ impl Command for CommandImpl {
return simple_error!("Parse registration data failed: {}", e);
}
}
Ok(())
Ok(None)
}
}
//

View File

@@ -1,5 +1,4 @@
use clap::{ArgMatches, SubCommand, App, Arg};
use crate::cmd::{Command, CommandError};
use authenticator::{KeyHandle, AuthenticatorTransports, SignFlags};
use std::sync::mpsc::channel;
use authenticator::statecallback::StateCallback;
@@ -7,6 +6,7 @@ use authenticator::authenticatorservice::AuthenticatorService;
use crate::fido;
use crate::digest;
use crate::fido::U2fV2Challenge;
use rust_util::util_clap::{Command, CommandError};
pub struct CommandImpl;
@@ -83,6 +83,6 @@ impl Command for CommandImpl {
// u2f::authorization::parse_sign_response(app_id.to_string(), u2fv2_challenge_str.as_bytes().to_vec(), )
Ok(())
Ok(None)
}
}