get_txc!() now assumes the OpenPGP application should be re-selected, by default
This commit is contained in:
parent
6100ec4318
commit
36b9fb2770
6 changed files with 23 additions and 18 deletions
|
@ -10,7 +10,7 @@ fn main() -> Result<()> {
|
|||
println!("The following OpenPGP cards are connected to your system:");
|
||||
|
||||
for mut card in PcscCard::cards()? {
|
||||
let mut txc: TxClient = openpgp_card_pcsc::get_txc!(card, true)?;
|
||||
let mut txc: TxClient = openpgp_card_pcsc::get_txc!(card)?;
|
||||
|
||||
let open = Open::new(&mut txc)?;
|
||||
println!(" {}", open.application_identifier()?.ident());
|
||||
|
|
|
@ -682,8 +682,8 @@ pub fn run_test(
|
|||
|
||||
use anyhow::anyhow;
|
||||
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card_client, true)
|
||||
.map_err(|e| anyhow!(e))?;
|
||||
let mut txc =
|
||||
openpgp_card_pcsc::get_txc!(card_client).map_err(|e| anyhow!(e))?;
|
||||
// let mut txc = TxClient::new(&mut tx, card_caps, reader_caps);
|
||||
|
||||
t(&mut txc, param)
|
||||
|
|
|
@ -36,7 +36,7 @@ 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 txc = openpgp_card_pcsc::get_txc!(card, true)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
// Open fresh Card for decrypt
|
||||
// -----------------------------
|
||||
let mut card = PcscCard::open_by_ident(&test_card_ident)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -188,7 +188,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
// Open fresh Card for signing
|
||||
// -----------------------------
|
||||
let mut card = PcscCard::open_by_ident(&test_card_ident)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -220,7 +220,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
println!("The following OpenPGP cards are connected to your system:");
|
||||
|
||||
for mut card in PcscCard::cards()? {
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card, true)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
|
||||
let open = Open::new(&mut txc)?;
|
||||
println!(" {}", open.application_identifier()?.ident());
|
||||
|
|
|
@ -20,10 +20,15 @@ const FEATURE_MODIFY_PIN_DIRECT: u8 = 0x07;
|
|||
/// in PcscCard)
|
||||
#[macro_export]
|
||||
macro_rules! get_txc {
|
||||
($card:expr, $reselect:expr) => {{
|
||||
($card:expr $(, $reselect:expr)? ) => {{
|
||||
use openpgp_card::{Error, SmartcardError};
|
||||
use pcsc::{Disposition, Protocols, ShareMode};
|
||||
// use std::collections::HashMap;
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
let mut reselect = true;
|
||||
$(
|
||||
reselect = $reselect;
|
||||
)?
|
||||
|
||||
let mut was_reset = false;
|
||||
|
||||
|
@ -52,7 +57,7 @@ macro_rules! get_txc {
|
|||
// For initial card-opening, we don't do this, then
|
||||
// the caller always expects a card that has not
|
||||
// been "select"ed yet.
|
||||
if $reselect {
|
||||
if reselect {
|
||||
TxClient::select(&mut txc)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let cli = cli::Cli::from_args();
|
||||
|
||||
let mut card = PcscCard::open_by_ident(&cli.ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let pinpad_verify = txc.feature_pinpad_verify();
|
||||
let pinpad_modify = txc.feature_pinpad_modify();
|
||||
|
|
|
@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
cmd,
|
||||
} => {
|
||||
let mut card = util::open_card(&ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -139,7 +139,7 @@ fn list_cards() -> Result<()> {
|
|||
println!("Available OpenPGP cards:");
|
||||
|
||||
for mut card in cards {
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let open = Open::new(&mut txc)?;
|
||||
println!(" {}", open.application_identifier()?.ident());
|
||||
|
@ -155,7 +155,7 @@ fn set_identity(
|
|||
id: u8,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
<dyn CardClient>::set_identity(&mut txc, id)?;
|
||||
|
||||
|
@ -174,7 +174,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -328,7 +328,7 @@ fn decrypt(
|
|||
let input = util::open_or_stdin(input.as_deref())?;
|
||||
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -354,7 +354,7 @@ fn sign_detached(
|
|||
let mut input = util::open_or_stdin(input.as_deref())?;
|
||||
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let mut open = Open::new(&mut txc)?;
|
||||
|
||||
|
@ -373,7 +373,7 @@ fn sign_detached(
|
|||
fn factory_reset(ident: &str) -> Result<()> {
|
||||
println!("Resetting Card {}", ident);
|
||||
let mut card = util::open_card(ident)?;
|
||||
let mut txc = get_txc!(card, true)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
Open::new(&mut txc)?.factory_reset()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue