Add test for key generation

This commit is contained in:
Sosthène Guédon
2022-12-16 11:34:08 +01:00
parent 0d6580c1c8
commit ce28dcb189
2 changed files with 28 additions and 5 deletions
+17
View File
@@ -69,4 +69,21 @@
)
]
),
IoTest(
name: "Generate key",
cmd_resp: [
AuthenticateManagement(
key: (
algorithm: Tdes,
key: "0102030405060708 0102030405060708 0102030405060708"
)
),
IoData(
input: "00 47 009A 05
AC 03
80 01 11",
output: Len(70),
)
]
)
]
+11 -5
View File
@@ -197,8 +197,14 @@ enum OutputMatcher {
Len(usize),
// The () at the end are here to workaround a compiler bug. See:
// https://github.com/rust-lang/rust/issues/89940#issuecomment-1282321806
And(Cow<'static, [OutputMatcher]>, #[serde(default)] ()),
Or(Cow<'static, [OutputMatcher]>, #[serde(default)] ()),
All(
#[serde(default)] Cow<'static, [OutputMatcher]>,
#[serde(default)] (),
),
Any(
#[serde(default)] Cow<'static, [OutputMatcher]>,
#[serde(default)] (),
),
/// HEX data
Data(Cow<'static, str>),
Bytes(Cow<'static, [u8]>),
@@ -229,8 +235,8 @@ impl OutputMatcher {
data == &**expected
}
Self::Len(len) => data.len() == *len,
Self::And(matchers, _) => matchers.iter().filter(|m| !m.validate(data)).count() == 0,
Self::Or(matchers, _) => matchers.iter().filter(|m| m.validate(data)).count() != 0,
Self::All(matchers, _) => matchers.iter().filter(|m| !m.validate(data)).count() == 0,
Self::Any(matchers, _) => matchers.iter().filter(|m| m.validate(data)).count() != 0,
}
}
}
@@ -276,7 +282,7 @@ enum IoCmd {
}
const MATCH_EMPTY: OutputMatcher = OutputMatcher::Len(0);
const MATCH_ANY: OutputMatcher = OutputMatcher::And(Cow::Borrowed(&[]), ());
const MATCH_ANY: OutputMatcher = OutputMatcher::All(Cow::Borrowed(&[]), ());
impl IoCmd {
fn run(&self, card: &mut setup::Piv) {