diff --git a/kbkdf/src/lib.rs b/kbkdf/src/lib.rs index b5e1a42..96c3f16 100644 --- a/kbkdf/src/lib.rs +++ b/kbkdf/src/lib.rs @@ -127,7 +127,7 @@ where /// - Prf - the Pseudorandom Function to derive keys from /// - K - the expected output length of the newly derived key /// - R - An integer (1 <= r <= 32) that indicates the length of the binary encoding of the counter i -/// as an integer in the interval [1, 2r − 1]. +/// as an integer in the interval [1, 2r − 1]. pub trait Kbkdf where Prf: Mac + KeyInit, diff --git a/kbkdf/src/tests.rs b/kbkdf/src/tests.rs index df89e2b..0345406 100644 --- a/kbkdf/src/tests.rs +++ b/kbkdf/src/tests.rs @@ -79,7 +79,7 @@ fn test_static_values_counter() { .with_context(v.context) .build() ), - Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()), + Ok(Array::<_, _>::try_from(v.expected).unwrap()), "key derivation failed for (index: {i}):\n{v:x?}" ); } @@ -97,13 +97,22 @@ fn test_counter_kbkdfvs() { let counter = Counter::::default(); // KDFCTR_gen.txt count 15 assert_eq!( - counter.derive(Params::builder( - &hex!("43eef6d824fd820405626ab9b6d79f1fd04e126ab8e17729e3afc7cb5af794f8")).use_l(false).use_separator( - false).with_label( - &hex!("5e269b5a7bdedcc3e875e2725693a257fc60011af7dcd68a3358507fe29b0659ca66951daa05a15032033650bc58a27840f8fbe9f4088b9030738f68")).build() - ), - Ok(Array::::from(hex!("f0a339ecbcae6add1afb27da3ba40a1320c6427a58afb9dc366b219b7eb29ecf")).clone()), - ); + counter.derive( + Params::builder(&hex!( + "43eef6d824fd820405626ab9b6d79f1fd04e126ab8e17729e3afc7cb5af794f8" + )) + .use_l(false) + .use_separator(false) + .with_label(&hex!( + "5e269b5a7bdedcc3e875e2725693a257fc60011af7dcd68a3358507fe29b0659" + "ca66951daa05a15032033650bc58a27840f8fbe9f4088b9030738f68" + )) + .build() + ), + Ok(Array::::from(hex!( + "f0a339ecbcae6add1afb27da3ba40a1320c6427a58afb9dc366b219b7eb29ecf" + ))), + ); } static KNOWN_VALUES_FEEDBACK_HMAC_SHA256: &[KnownValue] = &[ @@ -172,7 +181,7 @@ fn test_static_values_feedback() { .with_context(v.context) .build() ), - Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()), + Ok(Array::<_, _>::try_from(v.expected).unwrap()), "key derivation failed for (index: {i}):\n{v:x?}" ); } @@ -215,7 +224,7 @@ fn test_static_values_double_pipeline() { .with_context(v.context) .build(), ), - Ok(Array::<_, _>::try_from(v.expected).unwrap().clone()), + Ok(Array::<_, _>::try_from(v.expected).unwrap()), "key derivation failed for (index: {i}):\n{v:x?}" ); } diff --git a/kbkdf/tests/kbkdf/parser.rs b/kbkdf/tests/kbkdf/parser.rs index 554f762..5e48ce9 100644 --- a/kbkdf/tests/kbkdf/parser.rs +++ b/kbkdf/tests/kbkdf/parser.rs @@ -1,5 +1,4 @@ use digest::consts::*; -use hex; use kbkdf::{Kbkdf, Params}; use core::{convert::TryInto, ops::Mul}; @@ -43,10 +42,8 @@ impl Prf { } fn is_supported(&self) -> bool { - match self { - Self::CmacTdes2 | Self::CmacTdes3 => false, - _ => true, - } + let not_supported = matches!(self, Self::CmacTdes2 | Self::CmacTdes3); + !not_supported } } @@ -72,10 +69,7 @@ impl CounterLocation { } fn is_supported(&self) -> bool { - match self { - Self::Before | Self::AfterIter => true, - _ => false, - } + matches!(self, Self::Before | Self::AfterIter) } } @@ -431,11 +425,11 @@ fn eval_test_vectors(data: &str, use_counter: bool) -> Option<()> { } // Read and parse KBKDF configuration. - let prf = Prf::from_str(&l); + let prf = Prf::from_str(l); let (counter_location, r_len) = if use_counter { ( CounterLocation::from_str(data.next().unwrap()), - Rlen::from_str(&data.next().unwrap()), + Rlen::from_str(data.next().unwrap()), ) } else { // Counter location and r-len are not needed and do not present in a test file.