Where possible, avoid unnecessary boxing.
This commit is contained in:
parent
0c86fcb84a
commit
64119c4f29
3 changed files with 12 additions and 9 deletions
|
@ -106,8 +106,10 @@ impl TestCard {
|
|||
let card: Result<Box<dyn CardBackend>, Error> = loop {
|
||||
let res = PcscBackend::open_by_ident(ident, SHARE_MODE);
|
||||
|
||||
if i == 3 || res.is_ok() {
|
||||
break res.map(Into::into);
|
||||
if i == 3 {
|
||||
if let Ok(res) = res {
|
||||
break Ok(Box::new(res));
|
||||
}
|
||||
}
|
||||
|
||||
// sleep for 100ms
|
||||
|
|
|
@ -13,6 +13,7 @@ use sequoia_openpgp::Cert;
|
|||
|
||||
use openpgp_card::algorithm::AlgoSimple;
|
||||
use openpgp_card::{card_do::Sex, KeyType};
|
||||
use openpgp_card::CardBackend;
|
||||
|
||||
use openpgp_card_sequoia::card::{Admin, Open};
|
||||
use openpgp_card_sequoia::util::{make_cert, public_key_material_to_key};
|
||||
|
@ -162,12 +163,12 @@ fn set_identity(
|
|||
}
|
||||
|
||||
fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
|
||||
let mut card = if let Some(ident) = ident {
|
||||
util::open_card(&ident)?
|
||||
let mut card: Box<dyn CardBackend> = if let Some(ident) = ident {
|
||||
Box::new(util::open_card(&ident)?)
|
||||
} else {
|
||||
let mut cards = util::cards()?;
|
||||
if cards.len() == 1 {
|
||||
cards.pop().unwrap()
|
||||
Box::new(cards.pop().unwrap())
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("Found {} cards", cards.len()));
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ use openpgp_card::{CardBackend, Error};
|
|||
use openpgp_card_pcsc::PcscBackend;
|
||||
use openpgp_card_sequoia::card::{Admin, Open, Sign, User};
|
||||
|
||||
pub(crate) fn cards() -> Result<Vec<Box<dyn CardBackend>>, Error> {
|
||||
pub(crate) fn cards() -> Result<Vec<impl CardBackend>, Error> {
|
||||
PcscBackend::cards(None)
|
||||
.map(|cards| cards.into_iter().map(Into::into).collect())
|
||||
.map(|cards| cards.into_iter().collect())
|
||||
}
|
||||
|
||||
pub(crate) fn open_card(ident: &str) -> Result<Box<dyn CardBackend>, Error> {
|
||||
PcscBackend::open_by_ident(ident, None).map(Into::into)
|
||||
pub(crate) fn open_card(ident: &str) -> Result<impl CardBackend, Error> {
|
||||
PcscBackend::open_by_ident(ident, None)
|
||||
}
|
||||
|
||||
pub(crate) fn verify_to_user<'app, 'open>(
|
||||
|
|
Loading…
Reference in a new issue