feat: add openpgp card list
This commit is contained in:
@@ -6,6 +6,7 @@ mod fido;
|
||||
mod digest;
|
||||
mod register;
|
||||
mod sign;
|
||||
mod pgpcardlist;
|
||||
|
||||
use clap::{App, AppSettings};
|
||||
use cmd::{Command, CommandError};
|
||||
@@ -15,6 +16,7 @@ fn main() -> CommandError {
|
||||
let commands: Vec<Box<dyn Command>> = vec![
|
||||
Box::new(register::CommandImpl),
|
||||
Box::new(sign::CommandImpl),
|
||||
Box::new(pgpcardlist::CommandImpl),
|
||||
];
|
||||
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
|
||||
40
src/pgpcardlist.rs
Normal file
40
src/pgpcardlist.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use clap::{ArgMatches, SubCommand, App, Arg};
|
||||
use crate::cmd::{Command, CommandError};
|
||||
use openpgp_card::OpenPGPCard;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> &str { "pgp-card-list" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("OpenPGP Card List subcommand")
|
||||
// .arg(Arg::with_name("app-id").long("app-id").default_value("https://example.com").help("App id"))
|
||||
// .arg(Arg::with_name("timeout").long("timeout").default_value("10").help("Timeout in seconds"))
|
||||
.arg(Arg::with_name("json").long("json").help("JSON output"))
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
match OpenPGPCard::list_cards() {
|
||||
Err(e) => return simple_error!("Failed to list OpenPGP cards: {}", e),
|
||||
Ok(list) => {
|
||||
information!("Found {} card(s)", list.len());
|
||||
for (i, card) in list.iter().enumerate() {
|
||||
success!("Found card {}: {:?}", i, card.get_aid());
|
||||
if let Ok(fingerprints) = card.get_fingerprints() {
|
||||
if let Some(a) = fingerprints.authentication() {
|
||||
information!("Authentication fingerprint: {}", a);
|
||||
}
|
||||
if let Some(d) = fingerprints.decryption() {
|
||||
information!("Authentication fingerprint: {}", d);
|
||||
}
|
||||
if let Some(s) = fingerprints.signature() {
|
||||
information!("Authentication fingerprint: {}", s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user