feat: openpgp card test

This commit is contained in:
2022-03-27 22:29:40 +08:00
parent cf044ba7d0
commit 3a0956d651
3 changed files with 42 additions and 4 deletions

View File

@@ -1,16 +1,29 @@
use anyhow::Result; use anyhow::Result;
use openpgp_card::OpenPgp; use openpgp_card::OpenPgp;
use openpgp_card_pcsc::PcscBackend; use openpgp_card_pcsc::PcscBackend;
use openpgp_card_sequoia::card::Open;
fn main() -> Result<()> { fn main() -> Result<()> {
println!("The following OpenPGP cards are connected to your system:"); println!("The following OpenPGP cards are connected to your system:");
let cards = PcscBackend::cards(None).expect("list cards");
println!("Found {} cards", cards.len());
for mut card in PcscBackend::cards(None)? { for mut card in PcscBackend::cards(None)? {
let mut pgp = OpenPgp::new(&mut card); let mut pgp = OpenPgp::new(&mut card);
let open = Open::new(pgp.transaction()?)?; let mut trans = pgp.transaction()?;
println!(" {}", open.application_identifier()?.ident());
// println!("== {:?}", trans);
match trans.url() {
Ok(url) => println!("{}", String::from_utf8_lossy(&url)),
Err(e) => eprintln!("{:?}", e),
}
// trans.verify_pw1_user(b"123456").expect("verify p1 user pin");
// trans.verify_pw1_sign(b"123456").expect("verify p1 sign pin");
// trans.verify_pw3(b"12345678").expect("verify p3 pin");
// let open = Open::new(pgp.transaction()?)?;
// println!(" {}", open.application_identifier()?.ident());
} }
Ok(()) Ok(())

View File

@@ -0,0 +1,21 @@
use anyhow::Result;
use openpgp_card::OpenPgp;
use openpgp_card_pcsc::PcscBackend;
use openpgp_card_sequoia::card::Open;
fn main() -> Result<()> {
println!("The following OpenPGP cards are connected to your system:");
for mut card in PcscBackend::cards(None)? {
let mut pgp = OpenPgp::new(&mut card);
let open = Open::new(pgp.transaction()?)?;
println!(" {}", open.application_identifier()?.ident());
println!(" {}", open.application_identifier()?.application());
println!(" {}", open.application_identifier()?.version());
println!(" {:?}", open.fingerprints());
}
Ok(())
}

View File

@@ -5,4 +5,8 @@ _:
example_list_cards: example_list_cards:
cargo run --example list_cards cargo run --example list_cards
# example list pgp cards
example_list_pgp_cards:
cargo run --example list_pgp_cards