Copy card_caps information from PcscClient to PcscTxClient, if any
This commit is contained in:
parent
b6b2957580
commit
f4eaca229d
3 changed files with 20 additions and 17 deletions
|
@ -8,7 +8,6 @@ use anyhow::Result;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use openpgp_card::CardClient;
|
|
||||||
use openpgp_card_pcsc::PcscClient;
|
use openpgp_card_pcsc::PcscClient;
|
||||||
use openpgp_card_scdc::ScdClient;
|
use openpgp_card_scdc::ScdClient;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use openpgp_card;
|
||||||
use openpgp_card::algorithm::AlgoSimple;
|
use openpgp_card::algorithm::AlgoSimple;
|
||||||
use openpgp_card::card_do::{KeyGenerationTime, Sex};
|
use openpgp_card::card_do::{KeyGenerationTime, Sex};
|
||||||
use openpgp_card::{CardApp, CardClient, Error, KeyType, StatusBytes};
|
use openpgp_card::{CardApp, CardClient, Error, KeyType, StatusBytes};
|
||||||
use openpgp_card_pcsc::{PcscClient, PcscTxClient};
|
use openpgp_card_pcsc::PcscTxClient;
|
||||||
use openpgp_card_sequoia::card::Open;
|
use openpgp_card_sequoia::card::Open;
|
||||||
use openpgp_card_sequoia::util::{
|
use openpgp_card_sequoia::util::{
|
||||||
make_cert, public_key_material_to_key, public_to_fingerprint,
|
make_cert, public_key_material_to_key, public_to_fingerprint,
|
||||||
|
@ -702,12 +702,13 @@ pub fn run_test(
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use openpgp_card::SmartcardError;
|
use openpgp_card::SmartcardError;
|
||||||
use openpgp_card_pcsc::PcscTxClient;
|
|
||||||
use pcsc::Transaction;
|
use pcsc::Transaction;
|
||||||
|
|
||||||
|
let card_caps = card_client.card_caps();
|
||||||
|
|
||||||
let mut tx: Transaction = openpgp_card_pcsc::start_tx!(card_client.card())
|
let mut tx: Transaction = openpgp_card_pcsc::start_tx!(card_client.card())
|
||||||
.map_err(|e| anyhow!(e))?;
|
.map_err(|e| anyhow!(e))?;
|
||||||
let mut txc = PcscTxClient::new(&mut tx);
|
let mut txc = PcscTxClient::new(&mut tx, card_caps);
|
||||||
|
|
||||||
t(&mut txc, param)
|
t(&mut txc, param)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use iso7816_tlv::simple::Tlv;
|
use iso7816_tlv::simple::Tlv;
|
||||||
use pcsc::{
|
use pcsc::{Card, Context, Protocols, Scope, ShareMode, Transaction};
|
||||||
Card, Context, Disposition, Protocols, Scope, ShareMode, Transaction,
|
|
||||||
};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
@ -22,10 +20,7 @@ const FEATURE_MODIFY_PIN_DIRECT: u8 = 0x07;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! start_tx {
|
macro_rules! start_tx {
|
||||||
($card:expr) => {{
|
($card:expr) => {{
|
||||||
use pcsc::{
|
use pcsc::{Disposition, Protocols, ShareMode};
|
||||||
Card, Context, Disposition, Protocols, Scope, ShareMode,
|
|
||||||
Transaction,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut was_reset = false;
|
let mut was_reset = false;
|
||||||
|
|
||||||
|
@ -41,7 +36,7 @@ macro_rules! start_tx {
|
||||||
"start_tx: card was reset, select() openpgp"
|
"start_tx: card was reset, select() openpgp"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut txc = PcscTxClient::new(&mut tx);
|
let mut txc = PcscTxClient::new(&mut tx, None);
|
||||||
PcscTxClient::select(&mut txc)?;
|
PcscTxClient::select(&mut txc)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +89,15 @@ pub struct PcscClient {
|
||||||
|
|
||||||
pub struct PcscTxClient<'a, 'b> {
|
pub struct PcscTxClient<'a, 'b> {
|
||||||
tx: &'a mut Transaction<'b>,
|
tx: &'a mut Transaction<'b>,
|
||||||
|
card_caps: Option<CardCaps>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> PcscTxClient<'a, 'b> {
|
impl<'a, 'b> PcscTxClient<'a, 'b> {
|
||||||
pub fn new(tx: &'a mut Transaction<'b>) -> Self {
|
pub fn new(
|
||||||
PcscTxClient { tx }
|
tx: &'a mut Transaction<'b>,
|
||||||
|
card_caps: Option<CardCaps>,
|
||||||
|
) -> Self {
|
||||||
|
PcscTxClient { tx, card_caps }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ impl CardClient for PcscTxClient<'_, '_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn card_caps(&self) -> Option<&CardCaps> {
|
fn card_caps(&self) -> Option<&CardCaps> {
|
||||||
None
|
self.card_caps.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn feature_pinpad_verify(&self) -> bool {
|
fn feature_pinpad_verify(&self) -> bool {
|
||||||
|
@ -263,7 +262,7 @@ impl PcscClient {
|
||||||
log::debug!("1");
|
log::debug!("1");
|
||||||
let mut tx: Transaction = start_tx!(card)?;
|
let mut tx: Transaction = start_tx!(card)?;
|
||||||
|
|
||||||
let mut txc = PcscTxClient::new(&mut tx);
|
let mut txc = PcscTxClient::new(&mut tx, None);
|
||||||
log::debug!("3");
|
log::debug!("3");
|
||||||
{
|
{
|
||||||
if let Err(e) = PcscTxClient::select(&mut txc) {
|
if let Err(e) = PcscTxClient::select(&mut txc) {
|
||||||
|
@ -416,6 +415,10 @@ impl PcscClient {
|
||||||
|
|
||||||
Ok(Tlv::parse_all(res))
|
Ok(Tlv::parse_all(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn card_caps(&self) -> Option<CardCaps> {
|
||||||
|
self.card_caps
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CardClient for PcscClient {
|
impl CardClient for PcscClient {
|
||||||
|
@ -430,7 +433,7 @@ impl CardClient for PcscClient {
|
||||||
let mut tx: Transaction = start_tx!(self.card)?;
|
let mut tx: Transaction = start_tx!(self.card)?;
|
||||||
|
|
||||||
log::debug!("PcscClient transmit 2");
|
log::debug!("PcscClient transmit 2");
|
||||||
let mut txc = PcscTxClient::new(&mut tx);
|
let mut txc = PcscTxClient::new(&mut tx, self.card_caps);
|
||||||
log::debug!("PcscClient transmit 3 (got TxClient!)");
|
log::debug!("PcscClient transmit 3 (got TxClient!)");
|
||||||
|
|
||||||
let res = txc.transmit(cmd, buf_size);
|
let res = txc.transmit(cmd, buf_size);
|
||||||
|
|
Loading…
Reference in a new issue