38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
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),
|
|
}
|
|
}
|
|
|
|
pub fn get_card_user_sw1_82(pass: &str) -> XResult<OpenPGPCardUser> {
|
|
match OpenPGPCard::list_cards() {
|
|
Ok(list) => {
|
|
// pw1_82 for decrypt
|
|
// PKCSv1.5
|
|
if list.is_empty() {
|
|
return simple_error!("Cannot find any card");
|
|
}
|
|
match list.into_iter().next().unwrap().verify_pw1_82(pass) {
|
|
Result::Ok(user) => Ok(user),
|
|
Result::Err(_) => simple_error!("Verify pw1_82 OpenPGP card failed"),
|
|
}
|
|
}
|
|
Err(e) => simple_error!("Read OpenPGP card failed: {}", e),
|
|
}
|
|
}
|
|
|