Refactor card initialisation
This commit is contained in:
parent
38fb6bd970
commit
7afe2f52c2
2 changed files with 35 additions and 28 deletions
|
@ -45,6 +45,39 @@ impl CardApp {
|
|||
self.card_client
|
||||
}
|
||||
|
||||
/// Read capabilities from the card, and set them in the CardApp
|
||||
pub fn init_caps(mut self, ard: &Tlv) -> Result<Self> {
|
||||
// Determine chaining/extended length support from card
|
||||
// metadata and cache this information in CardApp (as a
|
||||
// CardCaps)
|
||||
|
||||
let mut ext_support = false;
|
||||
let mut chaining_support = false;
|
||||
|
||||
if let Ok(hist) = CardApp::get_historical(&ard) {
|
||||
if let Some(cc) = hist.get_card_capabilities() {
|
||||
chaining_support = cc.get_command_chaining();
|
||||
ext_support = cc.get_extended_lc_le();
|
||||
}
|
||||
}
|
||||
|
||||
let max_cmd_bytes = if let Ok(Some(eli)) =
|
||||
CardApp::get_extended_length_information(&ard)
|
||||
{
|
||||
eli.max_command_bytes
|
||||
} else {
|
||||
255
|
||||
};
|
||||
|
||||
let caps = CardCaps {
|
||||
ext_support,
|
||||
chaining_support,
|
||||
max_cmd_bytes,
|
||||
};
|
||||
|
||||
Ok(self.set_caps(caps))
|
||||
}
|
||||
|
||||
pub fn set_caps(self, card_caps: CardCaps) -> Self {
|
||||
Self {
|
||||
card_client: self.card_client,
|
||||
|
|
|
@ -314,36 +314,10 @@ impl CardBase {
|
|||
pub fn open_card(ccb: CardClientBox) -> Result<Self, OpenpgpCardError> {
|
||||
// read and cache "application related data"
|
||||
let mut card_app = CardApp::new(ccb);
|
||||
|
||||
let ard = card_app.get_app_data()?;
|
||||
|
||||
// Determine chaining/extended length support from card
|
||||
// metadata and cache this information in CardApp (as a
|
||||
// CardCaps)
|
||||
|
||||
let mut ext_support = false;
|
||||
let mut chaining_support = false;
|
||||
|
||||
if let Ok(hist) = CardApp::get_historical(&ard) {
|
||||
if let Some(cc) = hist.get_card_capabilities() {
|
||||
chaining_support = cc.get_command_chaining();
|
||||
ext_support = cc.get_extended_lc_le();
|
||||
}
|
||||
}
|
||||
|
||||
let max_cmd_bytes = if let Ok(Some(eli)) =
|
||||
CardApp::get_extended_length_information(&ard)
|
||||
{
|
||||
eli.max_command_bytes
|
||||
} else {
|
||||
255
|
||||
};
|
||||
|
||||
let caps = CardCaps {
|
||||
ext_support,
|
||||
chaining_support,
|
||||
max_cmd_bytes,
|
||||
};
|
||||
let card_app = card_app.set_caps(caps);
|
||||
card_app = card_app.init_caps(&ard)?;
|
||||
|
||||
Ok(Self { card_app, ard })
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue