openpgp-card: use cache for immutable card settings
This commit is contained in:
parent
925d5c6f9c
commit
86ba745ea6
2 changed files with 17 additions and 19 deletions
|
@ -588,7 +588,7 @@ impl Display for KeyStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Application Identifier (AID) [Spec section 4.2.1]
|
/// Application Identifier (AID) [Spec section 4.2.1]
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub struct ApplicationIdentifier {
|
pub struct ApplicationIdentifier {
|
||||||
application: u8,
|
application: u8,
|
||||||
version: u16,
|
version: u16,
|
||||||
|
@ -607,7 +607,7 @@ impl Display for ApplicationIdentifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Historical Bytes [Spec chapter 6]
|
/// Historical Bytes [Spec chapter 6]
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct HistoricalBytes {
|
pub struct HistoricalBytes {
|
||||||
/// category indicator byte
|
/// category indicator byte
|
||||||
cib: u8,
|
cib: u8,
|
||||||
|
@ -623,7 +623,7 @@ pub struct HistoricalBytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Card Capabilities [Spec chapter 6 (Historical Bytes)]
|
/// Card Capabilities [Spec chapter 6 (Historical Bytes)]
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct CardCapabilities {
|
pub struct CardCapabilities {
|
||||||
command_chaining: bool,
|
command_chaining: bool,
|
||||||
extended_lc_le: bool,
|
extended_lc_le: bool,
|
||||||
|
@ -647,7 +647,7 @@ impl Display for CardCapabilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Card service data [Spec chapter 6 (Historical Bytes)]
|
/// Card service data [Spec chapter 6 (Historical Bytes)]
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct CardServiceData {
|
pub struct CardServiceData {
|
||||||
select_by_full_df_name: bool, // Application Selection by full DF name (AID)
|
select_by_full_df_name: bool, // Application Selection by full DF name (AID)
|
||||||
select_by_partial_df_name: bool, // Application Selection by partial DF name
|
select_by_partial_df_name: bool, // Application Selection by partial DF name
|
||||||
|
@ -694,7 +694,7 @@ impl Display for CardServiceData {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended Capabilities [Spec section 4.4.3.7]
|
/// Extended Capabilities [Spec section 4.4.3.7]
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, Clone, Copy, PartialEq)]
|
||||||
pub struct ExtendedCapabilities {
|
pub struct ExtendedCapabilities {
|
||||||
secure_messaging: bool,
|
secure_messaging: bool,
|
||||||
get_challenge: bool,
|
get_challenge: bool,
|
||||||
|
@ -784,7 +784,7 @@ impl Display for ExtendedCapabilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended length information [Spec section 4.1.3.1]
|
/// Extended length information [Spec section 4.1.3.1]
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, Clone, Copy, PartialEq)]
|
||||||
pub struct ExtendedLengthInfo {
|
pub struct ExtendedLengthInfo {
|
||||||
max_command_bytes: u16,
|
max_command_bytes: u16,
|
||||||
max_response_bytes: u16,
|
max_response_bytes: u16,
|
||||||
|
|
|
@ -392,32 +392,32 @@ impl<'a> Transaction<'a> {
|
||||||
///
|
///
|
||||||
/// This function returns data that is cached during initialization.
|
/// This function returns data that is cached during initialization.
|
||||||
/// Calling it doesn't require sending a command to the card.
|
/// Calling it doesn't require sending a command to the card.
|
||||||
pub fn application_identifier(&self) -> Result<&ApplicationIdentifier, Error> {
|
pub fn application_identifier(&self) -> Result<ApplicationIdentifier, Error> {
|
||||||
Ok(&self.card_immutable()?.aid)
|
Ok(self.card_immutable()?.aid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended capabilities.
|
/// Extended capabilities.
|
||||||
///
|
///
|
||||||
/// This function returns data that is cached during initialization.
|
/// This function returns data that is cached during initialization.
|
||||||
/// Calling it doesn't require sending a command to the card.
|
/// Calling it doesn't require sending a command to the card.
|
||||||
pub fn extended_capabilities(&self) -> Result<&ExtendedCapabilities, Error> {
|
pub fn extended_capabilities(&self) -> Result<ExtendedCapabilities, Error> {
|
||||||
Ok(&self.card_immutable()?.ec)
|
Ok(self.card_immutable()?.ec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Historical Bytes (if available).
|
/// Historical Bytes (if available).
|
||||||
///
|
///
|
||||||
/// This function returns data that is cached during initialization.
|
/// This function returns data that is cached during initialization.
|
||||||
/// Calling it doesn't require sending a command to the card.
|
/// Calling it doesn't require sending a command to the card.
|
||||||
pub fn historical_bytes(&self) -> Result<&Option<HistoricalBytes>, Error> {
|
pub fn historical_bytes(&self) -> Result<Option<HistoricalBytes>, Error> {
|
||||||
Ok(&self.card_immutable()?.hb)
|
Ok(self.card_immutable()?.hb)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extended length info (if available).
|
/// Extended length info (if available).
|
||||||
///
|
///
|
||||||
/// This function returns data that is cached during initialization.
|
/// This function returns data that is cached during initialization.
|
||||||
/// Calling it doesn't require sending a command to the card.
|
/// Calling it doesn't require sending a command to the card.
|
||||||
pub fn extended_length_info(&self) -> Result<&Option<ExtendedLengthInfo>, Error> {
|
pub fn extended_length_info(&self) -> Result<Option<ExtendedLengthInfo>, Error> {
|
||||||
Ok(&self.card_immutable()?.eli)
|
Ok(self.card_immutable()?.eli)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -1302,7 +1302,7 @@ impl<'a> Transaction<'a> {
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// An error is ok - it's fine if a card doesn't offer a list of
|
// An error is ok - it's fine if a card doesn't offer a list of
|
||||||
// supported algorithms
|
// supported algorithms
|
||||||
let algo_info = self.algorithm_information().unwrap_or(None);
|
let algo_info = self.algorithm_information_cached().ok().flatten();
|
||||||
|
|
||||||
keys::key_import(self, key, key_type, algo_info)
|
keys::key_import(self, key, key_type, algo_info)
|
||||||
}
|
}
|
||||||
|
@ -1328,9 +1328,7 @@ impl<'a> Transaction<'a> {
|
||||||
) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> {
|
) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> {
|
||||||
// Set algo on card if it's Some
|
// Set algo on card if it's Some
|
||||||
if let Some(target_algo) = algorithm_attributes {
|
if let Some(target_algo) = algorithm_attributes {
|
||||||
// FIXME: caching
|
let ecap = self.extended_capabilities()?;
|
||||||
let ard = self.application_related_data()?; // no caching, here!
|
|
||||||
let ecap = ard.extended_capabilities()?;
|
|
||||||
|
|
||||||
// Only set algo if card supports setting of algo attr
|
// Only set algo if card supports setting of algo attr
|
||||||
if ecap.algo_attrs_changeable() {
|
if ecap.algo_attrs_changeable() {
|
||||||
|
@ -1379,7 +1377,7 @@ impl<'a> Transaction<'a> {
|
||||||
let ard = self.application_related_data()?;
|
let ard = self.application_related_data()?;
|
||||||
let algorithm_attributes = ard.algorithm_attributes(key_type)?;
|
let algorithm_attributes = ard.algorithm_attributes(key_type)?;
|
||||||
|
|
||||||
let algo_info = self.algorithm_information().ok().flatten();
|
let algo_info = self.algorithm_information_cached().ok().flatten();
|
||||||
|
|
||||||
let algo = simple.determine_algo_attributes(key_type, algorithm_attributes, algo_info)?;
|
let algo = simple.determine_algo_attributes(key_type, algorithm_attributes, algo_info)?;
|
||||||
Self::generate_key(self, fp_from_pub, key_type, Some(&algo))
|
Self::generate_key(self, fp_from_pub, key_type, Some(&algo))
|
||||||
|
|
Loading…
Reference in a new issue