openpgp-card: rename RsaAttrs->RsaAttributes, EccAttrs->EccAttributes
This commit is contained in:
parent
423c9d23ee
commit
ff1afee7c5
4 changed files with 202 additions and 117 deletions
|
@ -162,8 +162,8 @@ pub struct AlgorithmInformation(pub(crate) Vec<(KeyType, AlgorithmAttributes)>);
|
|||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum AlgorithmAttributes {
|
||||
Rsa(RsaAttrs),
|
||||
Ecc(EccAttrs),
|
||||
Rsa(RsaAttributes),
|
||||
Ecc(EccAttributes),
|
||||
Unknown(Vec<u8>),
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ impl AlgorithmAttributes {
|
|||
}
|
||||
|
||||
/// Helper: generate `data` for algorithm attributes with RSA
|
||||
fn rsa_algo_attrs(algo_attrs: &RsaAttrs) -> Result<Vec<u8>, Error> {
|
||||
fn rsa_algo_attrs(algo_attrs: &RsaAttributes) -> Result<Vec<u8>, Error> {
|
||||
// Algorithm ID (01 = RSA (Encrypt or Sign))
|
||||
let mut algo_attributes = vec![0x01];
|
||||
|
||||
|
@ -249,15 +249,15 @@ impl AlgorithmAttributes {
|
|||
|
||||
/// RSA specific attributes of [`AlgorithmAttributes`]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct RsaAttrs {
|
||||
pub struct RsaAttributes {
|
||||
len_n: u16,
|
||||
len_e: u16,
|
||||
import_format: u8,
|
||||
}
|
||||
|
||||
impl RsaAttrs {
|
||||
impl RsaAttributes {
|
||||
pub fn new(len_n: u16, len_e: u16, import_format: u8) -> Self {
|
||||
RsaAttrs {
|
||||
Self {
|
||||
len_n,
|
||||
len_e,
|
||||
import_format,
|
||||
|
@ -279,13 +279,13 @@ impl RsaAttrs {
|
|||
|
||||
/// ECC specific attributes of [`AlgorithmAttributes`]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct EccAttrs {
|
||||
pub struct EccAttributes {
|
||||
ecc_type: EccType,
|
||||
curve: Curve,
|
||||
import_format: Option<u8>,
|
||||
}
|
||||
|
||||
impl EccAttrs {
|
||||
impl EccAttributes {
|
||||
pub fn new(ecc_type: EccType, curve: Curve, import_format: Option<u8>) -> Self {
|
||||
Self {
|
||||
ecc_type,
|
||||
|
@ -326,6 +326,7 @@ pub enum Curve {
|
|||
Cv25519,
|
||||
Ed448,
|
||||
X448,
|
||||
|
||||
Unknown(Vec<u8>),
|
||||
}
|
||||
|
||||
|
@ -344,7 +345,8 @@ impl Curve {
|
|||
Cv25519 => oid::CV25519,
|
||||
Ed448 => oid::ED448,
|
||||
X448 => oid::X448,
|
||||
Unknown(v) => v,
|
||||
|
||||
Unknown(oid) => oid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -372,7 +374,7 @@ impl TryFrom<&[u8]> for Curve {
|
|||
oid::ED448 => Ed448,
|
||||
oid::X448 => X448,
|
||||
|
||||
o => Unknown(o.to_vec()),
|
||||
_ => Unknown(oid.to_vec()),
|
||||
};
|
||||
|
||||
Ok(curve)
|
||||
|
|
|
@ -10,7 +10,7 @@ use nom::bytes::complete::tag;
|
|||
use nom::combinator::map;
|
||||
use nom::{branch, bytes::complete as bytes, number::complete as number};
|
||||
|
||||
use crate::algorithm::{AlgorithmAttributes, Curve, EccAttrs, RsaAttrs};
|
||||
use crate::algorithm::{AlgorithmAttributes, Curve, EccAttributes, RsaAttributes};
|
||||
use crate::card_do::complete;
|
||||
use crate::crypto_data::EccType;
|
||||
|
||||
|
@ -89,7 +89,7 @@ fn parse_rsa(input: &[u8]) -> nom::IResult<&[u8], AlgorithmAttributes> {
|
|||
|
||||
Ok((
|
||||
input,
|
||||
AlgorithmAttributes::Rsa(RsaAttrs::new(len_n, len_e, import_format)),
|
||||
AlgorithmAttributes::Rsa(RsaAttributes::new(len_n, len_e, import_format)),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ fn parse_ecdh(input: &[u8]) -> nom::IResult<&[u8], AlgorithmAttributes> {
|
|||
|
||||
Ok((
|
||||
input,
|
||||
AlgorithmAttributes::Ecc(EccAttrs::new(EccType::ECDH, curve, import_format)),
|
||||
AlgorithmAttributes::Ecc(EccAttributes::new(EccType::ECDH, curve, import_format)),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ fn parse_ecdsa(input: &[u8]) -> nom::IResult<&[u8], AlgorithmAttributes> {
|
|||
|
||||
Ok((
|
||||
input,
|
||||
AlgorithmAttributes::Ecc(EccAttrs::new(EccType::ECDSA, curve, import_format)),
|
||||
AlgorithmAttributes::Ecc(EccAttributes::new(EccType::ECDSA, curve, import_format)),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ fn parse_eddsa(input: &[u8]) -> nom::IResult<&[u8], AlgorithmAttributes> {
|
|||
|
||||
Ok((
|
||||
input,
|
||||
AlgorithmAttributes::Ecc(EccAttrs::new(EccType::EdDSA, curve, import_format)),
|
||||
AlgorithmAttributes::Ecc(EccAttributes::new(EccType::EdDSA, curve, import_format)),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ mod test {
|
|||
use std::convert::TryFrom;
|
||||
|
||||
use crate::algorithm::{
|
||||
AlgorithmAttributes::*, AlgorithmInformation, Curve::*, EccAttrs, RsaAttrs,
|
||||
AlgorithmAttributes::*, AlgorithmInformation, Curve::*, EccAttributes, RsaAttributes,
|
||||
};
|
||||
use crate::crypto_data::EccType::*;
|
||||
use crate::KeyType::*;
|
||||
|
@ -125,21 +125,30 @@ mod test {
|
|||
assert_eq!(
|
||||
ai,
|
||||
AlgorithmInformation(vec![
|
||||
(Signing, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Signing, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(EdDSA, Ed25519, None))),
|
||||
(Decryption, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, Cv25519, None))),
|
||||
(Authentication, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(EdDSA, Ed25519, None)))
|
||||
(Signing, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Signing, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, Secp256k1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(EdDSA, Ed25519, None))),
|
||||
(Decryption, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDSA, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDSA, Secp256k1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, Cv25519, None))),
|
||||
(Authentication, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, NistP256r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, Secp256k1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(EdDSA, Ed25519, None))
|
||||
)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
@ -171,41 +180,68 @@ mod test {
|
|||
assert_eq!(
|
||||
ai,
|
||||
AlgorithmInformation(vec![
|
||||
(Signing, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Signing, Rsa(RsaAttrs::new(3072, 32, 0))),
|
||||
(Signing, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP384r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP521r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP256r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP384r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP512r1, None))),
|
||||
(Decryption, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttrs::new(3072, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP384r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP521r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP256r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP384r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP512r1, None))),
|
||||
(Authentication, Rsa(RsaAttrs::new(2048, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttrs::new(3072, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttrs::new(4096, 32, 0))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP384r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP521r1, None))),
|
||||
(Signing, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Signing, Rsa(RsaAttributes::new(3072, 32, 0))),
|
||||
(Signing, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP384r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP521r1, None))),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP512r1, None))
|
||||
),
|
||||
(Decryption, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttributes::new(3072, 32, 0))),
|
||||
(Decryption, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP384r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP521r1, None))),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP512r1, None))
|
||||
),
|
||||
(Authentication, Rsa(RsaAttributes::new(2048, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttributes::new(3072, 32, 0))),
|
||||
(Authentication, Rsa(RsaAttributes::new(4096, 32, 0))),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP256r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP256r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP384r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP384r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP512r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP521r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP512r1, None))
|
||||
)
|
||||
])
|
||||
);
|
||||
|
@ -252,72 +288,117 @@ mod test {
|
|||
assert_eq!(
|
||||
ai,
|
||||
AlgorithmInformation(vec![
|
||||
(Signing, Rsa(RsaAttrs::new(2048, 17, 0))),
|
||||
(Signing, Rsa(RsaAttrs::new(3072, 17, 0))),
|
||||
(Signing, Rsa(RsaAttrs::new(4096, 17, 0))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP384r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, NistP521r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP256r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP384r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(ECDSA, BrainpoolP512r1, None))),
|
||||
(Signing, Ecc(EccAttrs::new(EdDSA, Ed25519, None))),
|
||||
(Signing, Ecc(EccAttrs::new(EdDSA, Cv25519, None))),
|
||||
(Decryption, Rsa(RsaAttrs::new(2048, 17, 0))),
|
||||
(Decryption, Rsa(RsaAttrs::new(3072, 17, 0))),
|
||||
(Decryption, Rsa(RsaAttrs::new(4096, 17, 0))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP384r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, NistP521r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, Secp256k1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP256r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP384r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(ECDH, BrainpoolP512r1, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(EdDSA, Ed25519, None))),
|
||||
(Decryption, Ecc(EccAttrs::new(EdDSA, Cv25519, None))),
|
||||
(Authentication, Rsa(RsaAttrs::new(2048, 17, 0))),
|
||||
(Authentication, Rsa(RsaAttrs::new(3072, 17, 0))),
|
||||
(Authentication, Rsa(RsaAttrs::new(4096, 17, 0))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP384r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, NistP521r1, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(Signing, Rsa(RsaAttributes::new(2048, 17, 0))),
|
||||
(Signing, Rsa(RsaAttributes::new(3072, 17, 0))),
|
||||
(Signing, Rsa(RsaAttributes::new(4096, 17, 0))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP256r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP384r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, NistP521r1, None))),
|
||||
(Signing, Ecc(EccAttributes::new(ECDSA, Secp256k1, None))),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Signing,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP512r1, None))
|
||||
),
|
||||
(Signing, Ecc(EccAttributes::new(EdDSA, Ed25519, None))),
|
||||
(Signing, Ecc(EccAttributes::new(EdDSA, Cv25519, None))),
|
||||
(Decryption, Rsa(RsaAttributes::new(2048, 17, 0))),
|
||||
(Decryption, Rsa(RsaAttributes::new(3072, 17, 0))),
|
||||
(Decryption, Rsa(RsaAttributes::new(4096, 17, 0))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP256r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP384r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, NistP521r1, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(ECDH, Secp256k1, None))),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Decryption,
|
||||
Ecc(EccAttributes::new(ECDH, BrainpoolP512r1, None))
|
||||
),
|
||||
(Decryption, Ecc(EccAttributes::new(EdDSA, Ed25519, None))),
|
||||
(Decryption, Ecc(EccAttributes::new(EdDSA, Cv25519, None))),
|
||||
(Authentication, Rsa(RsaAttributes::new(2048, 17, 0))),
|
||||
(Authentication, Rsa(RsaAttributes::new(3072, 17, 0))),
|
||||
(Authentication, Rsa(RsaAttributes::new(4096, 17, 0))),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP256r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP256r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP384r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP384r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP512r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP521r1, None))
|
||||
),
|
||||
(Authentication, Ecc(EccAttrs::new(EdDSA, Ed25519, None))),
|
||||
(Authentication, Ecc(EccAttrs::new(EdDSA, Cv25519, None))),
|
||||
(Attestation, Rsa(RsaAttrs::new(2048, 17, 0))),
|
||||
(Attestation, Rsa(RsaAttrs::new(3072, 17, 0))),
|
||||
(Attestation, Rsa(RsaAttrs::new(4096, 17, 0))),
|
||||
(Attestation, Ecc(EccAttrs::new(ECDSA, NistP256r1, None))),
|
||||
(Attestation, Ecc(EccAttrs::new(ECDSA, NistP384r1, None))),
|
||||
(Attestation, Ecc(EccAttrs::new(ECDSA, NistP521r1, None))),
|
||||
(Attestation, Ecc(EccAttrs::new(ECDSA, Secp256k1, None))),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, Secp256k1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP512r1, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(EdDSA, Ed25519, None))
|
||||
),
|
||||
(
|
||||
Authentication,
|
||||
Ecc(EccAttributes::new(EdDSA, Cv25519, None))
|
||||
),
|
||||
(Attestation, Rsa(RsaAttributes::new(2048, 17, 0))),
|
||||
(Attestation, Rsa(RsaAttributes::new(3072, 17, 0))),
|
||||
(Attestation, Rsa(RsaAttributes::new(4096, 17, 0))),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP256r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP256r1, None))
|
||||
),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP384r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP384r1, None))
|
||||
),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttrs::new(ECDSA, BrainpoolP512r1, None))
|
||||
Ecc(EccAttributes::new(ECDSA, NistP521r1, None))
|
||||
),
|
||||
(Attestation, Ecc(EccAttrs::new(EdDSA, Ed25519, None))),
|
||||
(Attestation, Ecc(EccAttrs::new(EdDSA, Cv25519, None)))
|
||||
(Attestation, Ecc(EccAttributes::new(ECDSA, Secp256k1, None))),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP256r1, None))
|
||||
),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP384r1, None))
|
||||
),
|
||||
(
|
||||
Attestation,
|
||||
Ecc(EccAttributes::new(ECDSA, BrainpoolP512r1, None))
|
||||
),
|
||||
(Attestation, Ecc(EccAttributes::new(EdDSA, Ed25519, None))),
|
||||
(Attestation, Ecc(EccAttributes::new(EdDSA, Cv25519, None)))
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::algorithm::{AlgorithmAttributes, AlgorithmInformation, Curve, EccAttrs, RsaAttrs};
|
||||
use crate::algorithm::{
|
||||
AlgorithmAttributes, AlgorithmInformation, Curve, EccAttributes, RsaAttributes,
|
||||
};
|
||||
use crate::apdu::command::Command;
|
||||
use crate::apdu::commands;
|
||||
use crate::card_do::{Fingerprint, KeyGenerationTime};
|
||||
|
@ -207,7 +209,7 @@ pub(crate) fn determine_rsa_attrs(
|
|||
key_type: KeyType,
|
||||
algo_attr: AlgorithmAttributes,
|
||||
algo_info: Option<AlgorithmInformation>,
|
||||
) -> Result<RsaAttrs, Error> {
|
||||
) -> Result<RsaAttributes, Error> {
|
||||
// Figure out suitable RSA algorithm parameters:
|
||||
|
||||
// Does the card offer a list of algorithms?
|
||||
|
@ -222,7 +224,7 @@ pub(crate) fn determine_rsa_attrs(
|
|||
if let AlgorithmAttributes::Rsa(rsa) = algo_attr {
|
||||
// If so, use the algorithm parameters from the card and
|
||||
// adjust the bit length based on the user-provided key.
|
||||
RsaAttrs::new(rsa_bits, rsa.len_e(), rsa.import_format())
|
||||
RsaAttributes::new(rsa_bits, rsa.len_e(), rsa.import_format())
|
||||
} else {
|
||||
// The card doesn't provide an algorithm list, and the
|
||||
// current algorithm on the card is not RSA.
|
||||
|
@ -235,7 +237,7 @@ pub(crate) fn determine_rsa_attrs(
|
|||
// list of which RSA parameters that model of card
|
||||
// supports]
|
||||
|
||||
RsaAttrs::new(rsa_bits, 32, 0)
|
||||
RsaAttributes::new(rsa_bits, 32, 0)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -249,7 +251,7 @@ pub(crate) fn determine_ecc_attrs(
|
|||
ecc_type: EccType,
|
||||
key_type: KeyType,
|
||||
algo_info: Option<AlgorithmInformation>,
|
||||
) -> Result<EccAttrs, crate::Error> {
|
||||
) -> Result<EccAttributes, crate::Error> {
|
||||
// If we have an algo_info, refuse upload if oid is not listed
|
||||
if let Some(algo_info) = algo_info {
|
||||
let algos = check_card_algo_ecc(algo_info, key_type, oid);
|
||||
|
@ -269,7 +271,7 @@ pub(crate) fn determine_ecc_attrs(
|
|||
// We do however, use import_format from algorithm information.
|
||||
|
||||
if !algos.is_empty() {
|
||||
return Ok(EccAttrs::new(
|
||||
return Ok(EccAttributes::new(
|
||||
ecc_type,
|
||||
Curve::try_from(oid)?,
|
||||
algos[0].import_format(),
|
||||
|
@ -280,7 +282,7 @@ pub(crate) fn determine_ecc_attrs(
|
|||
// Return a default when we have no algo_info.
|
||||
// (Do cards that support ecc but have no algo_info exist?)
|
||||
|
||||
Ok(EccAttrs::new(ecc_type, Curve::try_from(oid)?, None))
|
||||
Ok(EccAttributes::new(ecc_type, Curve::try_from(oid)?, None))
|
||||
}
|
||||
|
||||
/// Look up RsaAttrs parameters in algo_info based on key_type and rsa_bits
|
||||
|
@ -288,7 +290,7 @@ fn card_algo_rsa(
|
|||
algo_info: AlgorithmInformation,
|
||||
key_type: KeyType,
|
||||
rsa_bits: u16,
|
||||
) -> Result<RsaAttrs, Error> {
|
||||
) -> Result<RsaAttributes, Error> {
|
||||
// Find suitable algorithm parameters (from card's list of algorithms).
|
||||
|
||||
// Get Algos for this keytype
|
||||
|
@ -330,7 +332,7 @@ fn check_card_algo_ecc(
|
|||
algo_info: AlgorithmInformation,
|
||||
key_type: KeyType,
|
||||
oid: &[u8],
|
||||
) -> Vec<EccAttrs> {
|
||||
) -> Vec<EccAttributes> {
|
||||
// Find suitable algorithm parameters (from card's list of algorithms).
|
||||
|
||||
// Get Algos for this keytype
|
||||
|
@ -361,7 +363,7 @@ fn check_card_algo_ecc(
|
|||
fn rsa_key_import_cmd(
|
||||
key_type: KeyType,
|
||||
rsa_key: Box<dyn RSAKey>,
|
||||
rsa_attrs: &RsaAttrs,
|
||||
rsa_attrs: &RsaAttributes,
|
||||
) -> Result<Command, Error> {
|
||||
// Assemble key command (see 4.4.3.12 Private Key Template)
|
||||
|
||||
|
@ -459,7 +461,7 @@ fn rsa_key_import_cmd(
|
|||
fn ecc_key_import_cmd(
|
||||
key_type: KeyType,
|
||||
ecc_key: Box<dyn EccKey>,
|
||||
ecc_attrs: &EccAttrs,
|
||||
ecc_attrs: &EccAttributes,
|
||||
) -> Result<Command, Error> {
|
||||
let private = ecc_key.private();
|
||||
|
||||
|
|
Loading…
Reference in a new issue