feat: update pgp

This commit is contained in:
2023-10-05 23:15:42 +08:00
parent 81c20a6872
commit 78824f279b
4 changed files with 14 additions and 9 deletions

View File

@@ -1,8 +1,9 @@
use clap::{App, Arg, ArgMatches, SubCommand};
use openpgp_card::card_do::{Lang, Sex};
use openpgp_card::OpenPgp;
use rust_util::util_clap::{Command, CommandError};
use crate::pgpcardutil;
pub struct CommandImpl;
impl Command for CommandImpl {
@@ -24,8 +25,7 @@ impl Command for CommandImpl {
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()); }
let card = crate::pgpcardutil::get_card()?;
let mut pgp = OpenPgp::new(card);
let mut pgp = pgpcardutil::get_openpgp_card()?;
let mut trans = opt_result!(pgp.transaction(), "Open card failed: {}");
if sub_arg_matches.is_present("reset") {

View File

@@ -2,10 +2,10 @@ use std::collections::BTreeMap;
use clap::{App, Arg, ArgMatches, SubCommand};
use openpgp_card::crypto_data::Cryptogram;
use openpgp_card::OpenPgp;
use rust_util::{util_msg, XResult};
use rust_util::util_clap::{Command, CommandError};
use crate::pgpcardutil;
use crate::util::{base64_decode, base64_encode};
#[derive(Debug, Clone, Copy)]
@@ -61,8 +61,7 @@ impl Command for CommandImpl {
return simple_error!("cipher or cipher-base64 must assign one");
};
let card = crate::pgpcardutil::get_card()?;
let mut pgp = OpenPgp::new(card);
let mut pgp = pgpcardutil::get_openpgp_card()?;
let mut trans = opt_result!(pgp.transaction(), "Open card failed: {}");
opt_result!(trans.verify_pw1_user(pin.as_ref()), "User pin verify failed: {}");

View File

@@ -5,10 +5,11 @@ use std::io::{ErrorKind, Read};
use clap::{App, Arg, ArgMatches, SubCommand};
use digest::Digest;
use openpgp_card::crypto_data::Hash;
use openpgp_card::OpenPgp;
use rust_util::util_clap::{Command, CommandError};
use rust_util::{util_msg, XResult};
use sha2::{Sha256, Sha384, Sha512};
use crate::pgpcardutil;
use crate::util::base64_encode;
const BUFF_SIZE: usize = 512 * 1024;
@@ -101,8 +102,7 @@ impl Command for CommandImpl {
return simple_error!("SHA256, SHA384 or SHA512 must assign at least one");
}
let card = crate::pgpcardutil::get_card()?;
let mut pgp = OpenPgp::new(card);
let mut pgp = pgpcardutil::get_openpgp_card()?;
let mut trans = opt_result!(pgp.transaction(), "Open card failed: {}");
if let Some(sha256) = sha256 {

View File

@@ -1,6 +1,12 @@
use openpgp_card::OpenPgp;
use openpgp_card_pcsc::PcscBackend;
use rust_util::XResult;
pub fn get_openpgp_card() -> XResult<OpenPgp> {
let card = get_card()?;
Ok(OpenPgp::new(card))
}
pub fn get_card() -> XResult<PcscBackend> {
let card_list = opt_result!(PcscBackend::cards(None), "Read OpenPGP card list failed: {}");
if card_list.is_empty() {