openpgp-card: internal API cleanup, continued
This commit is contained in:
parent
315aa7a94c
commit
9761e0e664
2 changed files with 13 additions and 15 deletions
|
@ -12,7 +12,6 @@
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::card_do::ApplicationRelatedData;
|
|
||||||
use crate::crypto_data::EccType;
|
use crate::crypto_data::EccType;
|
||||||
use crate::{keys, oid, Error, KeyType};
|
use crate::{keys, oid, Error, KeyType};
|
||||||
|
|
||||||
|
@ -77,38 +76,40 @@ impl AlgoSimple {
|
||||||
|
|
||||||
/// Return the appropriate Algo for this AlgoSimple.
|
/// Return the appropriate Algo for this AlgoSimple.
|
||||||
///
|
///
|
||||||
/// This mapping differs between cards, based on `ard` and `algo_info`
|
/// This mapping depends on the actual card in use
|
||||||
/// (e.g. the exact Algo variant can have a different size for e, in RSA;
|
/// (e.g.: the size of "e", in RSA can differ;
|
||||||
/// also, the import_format can differ).
|
/// or a different `import_format` can be selected).
|
||||||
|
///
|
||||||
|
/// These card-specific settings are derived from `algorithm_attributes` and `algo_info`.
|
||||||
pub(crate) fn determine_algo_attributes(
|
pub(crate) fn determine_algo_attributes(
|
||||||
&self,
|
&self,
|
||||||
key_type: KeyType,
|
key_type: KeyType,
|
||||||
ard: &ApplicationRelatedData,
|
algorithm_attributes: AlgorithmAttributes,
|
||||||
algo_info: Option<AlgoInfo>,
|
algo_info: Option<AlgoInfo>,
|
||||||
) -> Result<AlgorithmAttributes, Error> {
|
) -> Result<AlgorithmAttributes, Error> {
|
||||||
let algo = match self {
|
let algo = match self {
|
||||||
Self::RSA1k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
Self::RSA1k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
||||||
1024,
|
1024,
|
||||||
key_type,
|
key_type,
|
||||||
ard.algorithm_attributes(key_type)?,
|
algorithm_attributes,
|
||||||
algo_info,
|
algo_info,
|
||||||
)?),
|
)?),
|
||||||
Self::RSA2k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
Self::RSA2k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
||||||
2048,
|
2048,
|
||||||
key_type,
|
key_type,
|
||||||
ard.algorithm_attributes(key_type)?,
|
algorithm_attributes,
|
||||||
algo_info,
|
algo_info,
|
||||||
)?),
|
)?),
|
||||||
Self::RSA3k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
Self::RSA3k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
||||||
3072,
|
3072,
|
||||||
key_type,
|
key_type,
|
||||||
ard.algorithm_attributes(key_type)?,
|
algorithm_attributes,
|
||||||
algo_info,
|
algo_info,
|
||||||
)?),
|
)?),
|
||||||
Self::RSA4k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
Self::RSA4k => AlgorithmAttributes::Rsa(keys::determine_rsa_attrs(
|
||||||
4096,
|
4096,
|
||||||
key_type,
|
key_type,
|
||||||
ard.algorithm_attributes(key_type)?,
|
algorithm_attributes,
|
||||||
algo_info,
|
algo_info,
|
||||||
)?),
|
)?),
|
||||||
Self::NIST256 => AlgorithmAttributes::Ecc(keys::determine_ecc_attrs(
|
Self::NIST256 => AlgorithmAttributes::Ecc(keys::determine_ecc_attrs(
|
||||||
|
|
|
@ -1242,14 +1242,11 @@ impl<'a> Transaction<'a> {
|
||||||
simple: AlgoSimple,
|
simple: AlgoSimple,
|
||||||
) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> {
|
) -> Result<(PublicKeyMaterial, KeyGenerationTime), Error> {
|
||||||
let ard = self.application_related_data()?;
|
let ard = self.application_related_data()?;
|
||||||
let algo_info = if let Ok(ai) = self.algorithm_information() {
|
let algorithm_attributes = ard.algorithm_attributes(key_type)?;
|
||||||
ai
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let algo = simple.determine_algo_attributes(key_type, &ard, algo_info)?;
|
let algo_info = self.algorithm_information().ok().flatten();
|
||||||
|
|
||||||
|
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