Simplify optional $reselect parameter in get_txc!()
This commit is contained in:
parent
984aa219bf
commit
bdde317a2d
4 changed files with 14 additions and 18 deletions
|
@ -3,14 +3,14 @@
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use openpgp_card_pcsc::{PcscCard, TxClient};
|
||||
use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
|
||||
use openpgp_card_sequoia::card::Open;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
println!("The following OpenPGP cards are connected to your system:");
|
||||
|
||||
for mut card in PcscCard::cards(None)? {
|
||||
let mut txc: TxClient = openpgp_card_pcsc::get_txc!(card)?;
|
||||
let mut txc: TxClient = get_txc!(card)?;
|
||||
|
||||
let open = Open::new(&mut txc)?;
|
||||
println!(" {}", open.application_identifier()?.ident());
|
||||
|
|
|
@ -16,7 +16,7 @@ use openpgp_card;
|
|||
use openpgp_card::algorithm::AlgoSimple;
|
||||
use openpgp_card::card_do::{KeyGenerationTime, Sex};
|
||||
use openpgp_card::{CardClient, Error, KeyType, StatusBytes};
|
||||
use openpgp_card_pcsc::TxClient;
|
||||
use openpgp_card_pcsc::{get_txc, TxClient};
|
||||
use openpgp_card_sequoia::card::Open;
|
||||
use openpgp_card_sequoia::util::{
|
||||
make_cert, public_key_material_to_key, public_to_fingerprint,
|
||||
|
@ -682,8 +682,7 @@ pub fn run_test(
|
|||
|
||||
use anyhow::anyhow;
|
||||
|
||||
let mut txc =
|
||||
openpgp_card_pcsc::get_txc!(card_client).map_err(|e| anyhow!(e))?;
|
||||
let mut txc = get_txc!(card_client).map_err(|e| anyhow!(e))?;
|
||||
// let mut txc = TxClient::new(&mut tx, card_caps, reader_caps);
|
||||
|
||||
t(&mut txc, param)
|
||||
|
|
|
@ -11,7 +11,7 @@ use sequoia_openpgp::Cert;
|
|||
|
||||
use openpgp_card::card_do::Sex;
|
||||
use openpgp_card::KeyType;
|
||||
use openpgp_card_pcsc::{PcscCard, TxClient};
|
||||
use openpgp_card_pcsc::{get_txc, PcscCard, TxClient};
|
||||
|
||||
use openpgp_card_sequoia::card::Open;
|
||||
use openpgp_card_sequoia::sq_util;
|
||||
|
@ -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, None)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
let mut txc = 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, None)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
let mut txc = 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, None)?;
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
let mut txc = 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(None)? {
|
||||
let mut txc = openpgp_card_pcsc::get_txc!(card)?;
|
||||
let mut txc = get_txc!(card)?;
|
||||
|
||||
let open = Open::new(&mut txc)?;
|
||||
println!(" {}", open.application_identifier()?.ident());
|
||||
|
|
|
@ -20,16 +20,10 @@ 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};
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
let mut reselect = true;
|
||||
$(
|
||||
reselect = $reselect;
|
||||
)?
|
||||
|
||||
let mut was_reset = false;
|
||||
|
||||
let card_caps = $card.card_caps();
|
||||
|
@ -59,7 +53,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)?;
|
||||
}
|
||||
|
||||
|
@ -105,6 +99,9 @@ macro_rules! get_txc {
|
|||
};
|
||||
}
|
||||
}};
|
||||
( $card:expr ) => {
|
||||
get_txc!($card, true)
|
||||
};
|
||||
}
|
||||
|
||||
fn default_mode(mode: Option<ShareMode>) -> ShareMode {
|
||||
|
|
Loading…
Reference in a new issue