Separate test for reading ed25519 key from bad cbor

This commit is contained in:
Egor Duda
2022-05-13 22:06:10 +03:00
parent e473af7118
commit 3b8884c088

View File

@@ -540,23 +540,9 @@ mod test {
test_private_key_from_to_cbor(SignatureAlgorithm::EDDSA); test_private_key_from_to_cbor(SignatureAlgorithm::EDDSA);
} }
#[test] fn test_private_key_from_bad_cbor(signature_algorithm: SignatureAlgorithm) {
fn test_private_key_from_bad_cbor() {
let cbor = cbor_array![ let cbor = cbor_array![
cbor_int!(SignatureAlgorithm::ES256 as i64), cbor_int!(signature_algorithm as i64),
cbor_bytes!(vec![0x88; 32]),
// The array is too long.
cbor_int!(0),
];
assert_eq!(
PrivateKey::try_from(cbor),
Err(Ctap2StatusCode::CTAP2_ERR_INVALID_CBOR),
);
#[cfg(feature = "ed25519")]
{
let cbor = cbor_array![
cbor_int!(SignatureAlgorithm::EDDSA as i64),
cbor_bytes!(vec![0x88; 32]), cbor_bytes!(vec![0x88; 32]),
// The array is too long. // The array is too long.
cbor_int!(0), cbor_int!(0),
@@ -567,6 +553,19 @@ mod test {
); );
} }
#[test]
fn test_ecdsa_private_key_from_bad_cbor() {
test_private_key_from_bad_cbor(SignatureAlgorithm::ES256);
}
#[test]
#[cfg(feature = "ed25519")]
fn test_ed25519_private_key_from_bad_cbor() {
test_private_key_from_bad_cbor(SignatureAlgorithm::EDDSA);
}
#[test]
fn test_private_key_from_bad_cbor_unsupported_algo() {
let cbor = cbor_array![ let cbor = cbor_array![
// This algorithms doesn't exist. // This algorithms doesn't exist.
cbor_int!(-1), cbor_int!(-1),