Adjust openpgp-card-sequoia to changed openpgp-card API

This commit is contained in:
Heiko Schaefer 2022-01-19 18:09:34 +01:00
parent 1b1f6bc2df
commit 376072910e
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
3 changed files with 34 additions and 20 deletions

View file

@ -16,6 +16,7 @@ sequoia-openpgp = "1.4"
nettle = "7"
openpgp-card = { path = "../openpgp-card", version = "0.1" }
openpgp-card-pcsc = { path = "../pcsc", version = "0.1" }
pcsc = "2"
openpgp-card-scdc = { path = "../scdc", version = "0.1" }
chrono = "0.4"
anyhow = "1"

View file

@ -12,12 +12,13 @@
//! With `openpgp-card-pcsc` you can either open all available cards:
//!
//! ```no_run
//! use openpgp_card_pcsc::PcscCard;
//! use openpgp_card_sequoia::card::Open;
//! use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! for mut cc in PcscCard::cards()? {
//! let open = Open::new(&mut cc)?;
//! for mut card in PcscCard::cards()? {
//! let mut txc = get_txc!(card)?;
//! let open = Open::new(&mut txc)?;
//! println!("Found OpenPGP card with ident '{}'",
//! open.application_identifier()?.ident());
//! }
@ -28,12 +29,13 @@
//! Or you can open one particular card, by ident:
//!
//! ```no_run
//! use openpgp_card_pcsc::PcscCard;
//! use openpgp_card_sequoia::card::Open;
//! use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut cc = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut open = Open::new(&mut cc)?;
//! let mut card = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut txc = get_txc!(card)?;
//! let mut open = Open::new(&mut txc)?;
//! # Ok(())
//! # }
//! ```
@ -48,14 +50,15 @@
//! that corresponds to the private encryption key on the card:
//!
//! ```no_run
//! use openpgp_card_pcsc::PcscCard;
//! use openpgp_card_sequoia::card::Open;
//! use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open card via PCSC
//! use sequoia_openpgp::policy::StandardPolicy;
//! let mut cc = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut open = Open::new(&mut cc)?;
//! let mut card = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut txc = get_txc!(card)?;
//! let mut open = Open::new(&mut txc)?;
//!
//! // Get authorization for user access to the card with password
//! open.verify_user("123456")?;
@ -89,14 +92,15 @@
//! user password before each signing operation!)
//!
//! ```no_run
//! use openpgp_card_pcsc::PcscCard;
//! use openpgp_card_sequoia::card::Open;
//! use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open card via PCSC
//! use sequoia_openpgp::policy::StandardPolicy;
//! let mut cc = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut open = Open::new(&mut cc)?;
//! let mut card = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut txc = get_txc!(card)?;
//! let mut open = Open::new(&mut txc)?;
//!
//! // Get authorization for signing access to the card with password
//! open.verify_user_for_signing("123456")?;
@ -120,13 +124,14 @@
//! # Setting up and configuring a card
//!
//! ```no_run
//! use openpgp_card_pcsc::PcscCard;
//! use openpgp_card_sequoia::card::Open;
//! use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open card via PCSC
//! let mut cc = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut open = Open::new(&mut cc)?;
//! let mut card = PcscCard::open_by_ident("abcd:12345678")?;
//! let mut txc = get_txc!(card)?;
//! let mut open = Open::new(&mut txc)?;
//!
//! // Get authorization for admin access to the card with password
//! open.verify_admin("12345678")?;

View file

@ -11,7 +11,7 @@ use sequoia_openpgp::Cert;
use openpgp_card::card_do::Sex;
use openpgp_card::KeyType;
use openpgp_card_pcsc::PcscCard;
use openpgp_card_pcsc::{PcscCard, TxClient};
use openpgp_card_sequoia::card::Open;
use openpgp_card_sequoia::sq_util;
@ -36,7 +36,9 @@ fn main() -> Result<(), Box<dyn Error>> {
if let Ok(test_card_ident) = test_card_ident {
let mut card = PcscCard::open_by_ident(&test_card_ident)?;
let mut open = Open::new(&mut card)?;
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
let mut open = Open::new(&mut txc)?;
// card metadata
@ -145,7 +147,9 @@ fn main() -> Result<(), Box<dyn Error>> {
// Open fresh Card for decrypt
// -----------------------------
let mut card = PcscCard::open_by_ident(&test_card_ident)?;
let mut open = Open::new(&mut card)?;
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
let mut open = Open::new(&mut txc)?;
// Check that we're still using the expected card
let app_id = open.application_identifier()?;
@ -184,7 +188,9 @@ fn main() -> Result<(), Box<dyn Error>> {
// Open fresh Card for signing
// -----------------------------
let mut card = PcscCard::open_by_ident(&test_card_ident)?;
let mut open = Open::new(&mut card)?;
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
let mut open = Open::new(&mut txc)?;
// Sign
open.verify_user_for_signing("123456")?;
@ -214,7 +220,9 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("The following OpenPGP cards are connected to your system:");
for mut card in PcscCard::cards()? {
let open = Open::new(&mut card)?;
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
let open = Open::new(&mut txc)?;
println!(" {}", open.application_identifier()?.ident());
}
}