chore: add pgpcardutil.rs

This commit is contained in:
2021-07-11 10:02:30 +08:00
parent 98f4d475fb
commit 41724fd08e
3 changed files with 25 additions and 21 deletions

20
src/pgpcardutil.rs Normal file
View File

@@ -0,0 +1,20 @@
use rust_util::XResult;
use openpgp_card::{OpenPGPCardUser, OpenPGPCard};
pub fn get_card_user_sw1_81(pass: &str) -> XResult<OpenPGPCardUser> {
match OpenPGPCard::list_cards() {
Ok(list) => {
// pw1_81 for signature
// openssl dgst -sha256 -verify aa -signature sig LICENSE
if list.is_empty() {
return simple_error!("Cannot find any card");
}
match list.into_iter().next().unwrap().verify_pw1_81(pass) {
Result::Ok(user) => Ok(user),
Result::Err(_) => simple_error!("Verify pw1_81 OpenPGP card failed"),
}
}
Err(e) => simple_error!("Read OpenPGP card failed: {}", e),
}
}