feat: opt card logging
This commit is contained in:
@@ -5,6 +5,8 @@ use openpgp_card::Hash;
|
|||||||
use rust_util::util_clap::{Command, CommandError};
|
use rust_util::util_clap::{Command, CommandError};
|
||||||
use rust_util::XResult;
|
use rust_util::XResult;
|
||||||
|
|
||||||
|
use crate::pgpcardutil;
|
||||||
|
|
||||||
pub struct CommandImpl;
|
pub struct CommandImpl;
|
||||||
|
|
||||||
impl Command for CommandImpl {
|
impl Command for CommandImpl {
|
||||||
@@ -33,12 +35,12 @@ impl Command for CommandImpl {
|
|||||||
let sha512 = sub_arg_matches.value_of("sha512");
|
let sha512 = sub_arg_matches.value_of("sha512");
|
||||||
|
|
||||||
if sha256.is_none() && sha384.is_none() && sha512.is_none() {
|
if sha256.is_none() && sha384.is_none() && sha512.is_none() {
|
||||||
return simple_error!("SHA256, SHA384 or SHA512 must assign one");
|
return simple_error!("SHA256, SHA384 or SHA512 must assign at least one");
|
||||||
}
|
}
|
||||||
|
let user = opt_result!(pgpcardutil::get_card_user_sw1_81(pin), "Verify user pin failed: {}");
|
||||||
|
|
||||||
let mut json = BTreeMap::new();
|
let mut json = BTreeMap::new();
|
||||||
if let Some(sha256) = sha256 {
|
if let Some(sha256) = sha256 {
|
||||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
|
||||||
let sha256_hex = opt_result!(hex::decode(sha256.trim()), "Decode sha256 failed: {}");
|
let sha256_hex = opt_result!(hex::decode(sha256.trim()), "Decode sha256 failed: {}");
|
||||||
let sha256_hex = copy_sha256(&sha256_hex)?;
|
let sha256_hex = copy_sha256(&sha256_hex)?;
|
||||||
let sig = user.signature_for_hash(Hash::SHA256(sha256_hex))?;
|
let sig = user.signature_for_hash(Hash::SHA256(sha256_hex))?;
|
||||||
@@ -52,7 +54,6 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(sha384) = sha384 {
|
if let Some(sha384) = sha384 {
|
||||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
|
||||||
let sha384_hex = opt_result!(hex::decode(sha384.trim()), "Decode sha384 failed: {}");
|
let sha384_hex = opt_result!(hex::decode(sha384.trim()), "Decode sha384 failed: {}");
|
||||||
let sha384_hex = copy_sha384(&sha384_hex)?;
|
let sha384_hex = copy_sha384(&sha384_hex)?;
|
||||||
let sig = user.signature_for_hash(Hash::SHA384(sha384_hex))?;
|
let sig = user.signature_for_hash(Hash::SHA384(sha384_hex))?;
|
||||||
@@ -66,7 +67,6 @@ impl Command for CommandImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(sha512) = sha512 {
|
if let Some(sha512) = sha512 {
|
||||||
let user = crate::pgpcardutil::get_card_user_sw1_81(pin)?;
|
|
||||||
let sha512_hex = opt_result!(hex::decode(sha512.trim()), "Decode sha512 failed: {}");
|
let sha512_hex = opt_result!(hex::decode(sha512.trim()), "Decode sha512 failed: {}");
|
||||||
let sha512_hex = copy_sha512(&sha512_hex)?;
|
let sha512_hex = copy_sha512(&sha512_hex)?;
|
||||||
let sig = user.signature_for_hash(Hash::SHA512(sha512_hex))?;
|
let sig = user.signature_for_hash(Hash::SHA512(sha512_hex))?;
|
||||||
|
|||||||
@@ -35,9 +35,13 @@ fn get_card() -> XResult<OpenPGPCard> {
|
|||||||
if card_list.is_empty() {
|
if card_list.is_empty() {
|
||||||
return simple_error!("Cannot find any card");
|
return simple_error!("Cannot find any card");
|
||||||
}
|
}
|
||||||
if card_list.len() > 0 {
|
if card_list.len() > 1 {
|
||||||
warning!("Find {} OpenPGP cards, will use first card", card_list.len());
|
warning!("Find {} OpenPGP cards, will use first card", card_list.len());
|
||||||
}
|
}
|
||||||
Ok(opt_value_result!(card_list.into_iter().next(), "Get first card failed"))
|
let card = card_list.into_iter().next();
|
||||||
|
card.as_ref().map(|card|
|
||||||
|
card.get_aid().map(|card|
|
||||||
|
success!("Found card: {:?}", card)));
|
||||||
|
Ok(opt_value_result!(card, "Get first card failed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user