chore: add pgpcardutil.rs
This commit is contained in:
20
src/pgpcardutil.rs
Normal file
20
src/pgpcardutil.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user