Rename list_cards() -> cards().

Remove open_yolo() from the openpgp-card-pcsc API (it's easy enough to approximate by using cards())
This commit is contained in:
Heiko Schaefer 2021-09-10 14:34:33 +02:00
parent 55e7a2c794
commit 936f04663c
3 changed files with 5 additions and 19 deletions

View file

@ -97,7 +97,7 @@ impl TestCard {
let res = ScdClient::shutdown_scd(None); let res = ScdClient::shutdown_scd(None);
log::trace!(" Attempt to shutdown scd: {:?}", res); log::trace!(" Attempt to shutdown scd: {:?}", res);
for card_client in PcscClient::list_cards()? { for card_client in PcscClient::cards()? {
let mut ca = CardApp::from(card_client); let mut ca = CardApp::from(card_client);
// Set Card Capabilities (chaining, command length, ..) // Set Card Capabilities (chaining, command length, ..)

View file

@ -239,7 +239,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("The following OpenPGP cards are connected to your system:"); println!("The following OpenPGP cards are connected to your system:");
let cards = PcscClient::list_cards()?; let cards = PcscClient::cards()?;
for c in cards { for c in cards {
let mut ca = CardApp::from(c); let mut ca = CardApp::from(c);

View file

@ -82,7 +82,9 @@ impl PcscClient {
} }
/// Return all cards on which the OpenPGP application could be selected. /// Return all cards on which the OpenPGP application could be selected.
pub fn list_cards() -> Result<Vec<CardClientBox>> { ///
/// Each card is opened and has the OpenPGP application selected.
pub fn cards() -> Result<Vec<CardClientBox>> {
let cards = Self::unopened_cards()? let cards = Self::unopened_cards()?
.into_iter() .into_iter()
.map(Self::select) .map(Self::select)
@ -106,22 +108,6 @@ impl PcscClient {
} }
} }
/// Returns the first OpenPGP card, with the OpenPGP application selected.
///
/// If multiple cards are connected, this will effectively be a random
/// pick. You should consider using `open_by_ident` instead.
pub fn open_yolo() -> Result<CardClientBox, Error> {
for card in Self::unopened_cards()? {
if let Ok(ca) = Self::select(card) {
return Ok(ca.into());
}
}
Err(Error::Smartcard(SmartcardError::CardNotFound(
"No OpenPGP card found".to_string(),
)))
}
/// Get application related data from the card and check if 'ident' /// Get application related data from the card and check if 'ident'
/// matches /// matches
fn match_by_ident( fn match_by_ident(