pcsc: store reader name internally
The reader name could later be used as a source of information to signal reader limitations to callers (via CardCaps, e.g. readers that don't support extended length commands)
This commit is contained in:
parent
625df59c86
commit
0c07021043
1 changed files with 15 additions and 5 deletions
|
@ -26,6 +26,12 @@ pub struct PcscBackend {
|
||||||
card: pcsc::Card,
|
card: pcsc::Card,
|
||||||
mode: pcsc::ShareMode,
|
mode: pcsc::ShareMode,
|
||||||
reader_caps: HashMap<u8, Tlv>,
|
reader_caps: HashMap<u8, Tlv>,
|
||||||
|
|
||||||
|
// The reader name could be used as a hint about capabilities
|
||||||
|
// (e.g. readers that don't support extended length)
|
||||||
|
#[allow(dead_code)]
|
||||||
|
reader_name: String,
|
||||||
|
// FIXME: add a "adjust_card_caps" fn to card-backend? (could replace `max_cmd_len`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boxing helper (for easier consumption of PcscBackend in openpgp_card and openpgp_card_sequoia)
|
/// Boxing helper (for easier consumption of PcscBackend in openpgp_card and openpgp_card_sequoia)
|
||||||
|
@ -415,8 +421,9 @@ impl CardTransaction for PcscTransaction<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PcscBackend {
|
impl PcscBackend {
|
||||||
/// A list of "raw" opened PCSC Cards (without selecting any application)
|
/// A list of "raw" opened PCSC Cards and reader names
|
||||||
fn raw_pcsc_cards(mode: pcsc::ShareMode) -> Result<Vec<pcsc::Card>, SmartcardError> {
|
/// (No application is selected)
|
||||||
|
fn raw_pcsc_cards(mode: pcsc::ShareMode) -> Result<Vec<(pcsc::Card, String)>, SmartcardError> {
|
||||||
log::trace!("raw_pcsc_cards start");
|
log::trace!("raw_pcsc_cards start");
|
||||||
|
|
||||||
let ctx = match pcsc::Context::establish(pcsc::Scope::User) {
|
let ctx = match pcsc::Context::establish(pcsc::Scope::User) {
|
||||||
|
@ -445,7 +452,9 @@ impl PcscBackend {
|
||||||
|
|
||||||
// Find a reader with a SmartCard.
|
// Find a reader with a SmartCard.
|
||||||
for reader in readers {
|
for reader in readers {
|
||||||
log::trace!("Checking reader: {:?}", reader);
|
let name = String::from_utf8_lossy(reader.to_bytes());
|
||||||
|
|
||||||
|
log::trace!("Checking reader: {:?}", name);
|
||||||
|
|
||||||
// Try connecting to card in this reader
|
// Try connecting to card in this reader
|
||||||
let card = match ctx.connect(reader, mode, pcsc::Protocols::ANY) {
|
let card = match ctx.connect(reader, mode, pcsc::Protocols::ANY) {
|
||||||
|
@ -464,7 +473,7 @@ impl PcscBackend {
|
||||||
|
|
||||||
log::trace!("Found card");
|
log::trace!("Found card");
|
||||||
|
|
||||||
cards.push(card);
|
cards.push((card, name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cards)
|
Ok(cards)
|
||||||
|
@ -483,9 +492,10 @@ impl PcscBackend {
|
||||||
|
|
||||||
Ok(cards.into_iter().map(move |card| {
|
Ok(cards.into_iter().map(move |card| {
|
||||||
let backend = PcscBackend {
|
let backend = PcscBackend {
|
||||||
card,
|
card: card.0,
|
||||||
mode,
|
mode,
|
||||||
reader_caps: Default::default(),
|
reader_caps: Default::default(),
|
||||||
|
reader_name: card.1,
|
||||||
};
|
};
|
||||||
|
|
||||||
backend.initialize_card()
|
backend.initialize_card()
|
||||||
|
|
Loading…
Reference in a new issue