From ce28dcb189e3178589582f7b2ff4f77abaebb097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 1 Dec 2022 16:30:00 +0100 Subject: [PATCH] Add test for key generation --- tests/command_response.ron | 17 +++++++++++++++++ tests/command_response.rs | 16 +++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/command_response.ron b/tests/command_response.ron index 2b74bad..20b035f 100644 --- a/tests/command_response.ron +++ b/tests/command_response.ron @@ -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), + ) + ] + ) ] diff --git a/tests/command_response.rs b/tests/command_response.rs index bd865a3..4526238 100644 --- a/tests/command_response.rs +++ b/tests/command_response.rs @@ -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) {