From 752db8cc904165d4b5d54e38c2b0656cf0b3d571 Mon Sep 17 00:00:00 2001 From: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com> Date: Thu, 9 Mar 2023 12:08:34 +0100 Subject: [PATCH] Fixes new clippy lints on the latest nightly (#603) * Fixes new clippy lints on the latest nightly We didn't see these before because of our old Rust toolchain. * fixes nit --- libraries/opensk/src/api/upgrade_storage/helper.rs | 11 ++++------- libraries/opensk/src/ctap/apdu.rs | 2 +- libraries/opensk/src/ctap/client_pin.rs | 2 +- libraries/opensk/src/ctap/mod.rs | 2 ++ src/env/tock/storage.rs | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/opensk/src/api/upgrade_storage/helper.rs b/libraries/opensk/src/api/upgrade_storage/helper.rs index 6633f8f..697e6d0 100644 --- a/libraries/opensk/src/api/upgrade_storage/helper.rs +++ b/libraries/opensk/src/api/upgrade_storage/helper.rs @@ -150,15 +150,12 @@ impl ModRange { } } +#[derive(Default)] pub struct Partition { ranges: Vec, } impl Partition { - pub fn new() -> Partition { - Partition { ranges: Vec::new() } - } - /// Total length of all ranges. pub fn length(&self) -> usize { self.ranges.iter().map(|r| r.length()).sum() @@ -339,7 +336,7 @@ mod tests { #[test] fn partition_append() { - let mut partition = Partition::new(); + let mut partition = Partition::default(); partition.append(ModRange::new(0x4000, 0x1000)); partition.append(ModRange::new(0x20000, 0x20000)); partition.append(ModRange::new(0x40000, 0x20000)); @@ -349,7 +346,7 @@ mod tests { #[test] fn partition_find_address() { - let mut partition = Partition::new(); + let mut partition = Partition::default(); partition.append(ModRange::new(0x4000, 0x1000)); partition.append(ModRange::new(0x20000, 0x20000)); partition.append(ModRange::new(0x40000, 0x20000)); @@ -364,7 +361,7 @@ mod tests { #[test] fn partition_ranges_from() { - let mut partition = Partition::new(); + let mut partition = Partition::default(); partition.append(ModRange::new(0x4000, 0x1000)); partition.append(ModRange::new(0x20000, 0x20000)); partition.append(ModRange::new(0x40000, 0x20000)); diff --git a/libraries/opensk/src/ctap/apdu.rs b/libraries/opensk/src/ctap/apdu.rs index facb14f..8128855 100644 --- a/libraries/opensk/src/ctap/apdu.rs +++ b/libraries/opensk/src/ctap/apdu.rs @@ -118,7 +118,7 @@ impl TryFrom<&[u8]> for Apdu { type Error = ApduStatusCode; fn try_from(frame: &[u8]) -> Result { - if frame.len() < APDU_HEADER_LEN as usize { + if frame.len() < APDU_HEADER_LEN { return Err(ApduStatusCode::SW_WRONG_DATA); } // +-----+-----+----+----+ diff --git a/libraries/opensk/src/ctap/client_pin.rs b/libraries/opensk/src/ctap/client_pin.rs index 29d16f5..32d9c7f 100644 --- a/libraries/opensk/src/ctap/client_pin.rs +++ b/libraries/opensk/src/ctap/client_pin.rs @@ -1224,7 +1224,7 @@ mod test { ), // Reject PIN "12'\0'4" (a zero byte at index 2). ( - b"12\04".to_vec(), + [b'1', b'2', 0, b'4'].to_vec(), Err(Ctap2StatusCode::CTAP2_ERR_PIN_POLICY_VIOLATION), ), // PINs must be at most 63 bytes long, to allow for a trailing 0u8 padding. diff --git a/libraries/opensk/src/ctap/mod.rs b/libraries/opensk/src/ctap/mod.rs index a72d441..a10f78f 100644 --- a/libraries/opensk/src/ctap/mod.rs +++ b/libraries/opensk/src/ctap/mod.rs @@ -1513,6 +1513,8 @@ mod test { let mut ctap_state = CtapState::::new(&mut env); let info_reponse = ctap_state.process_command(&mut env, &[0x04], DUMMY_CHANNEL); + // Fails when removing `to_vec` for `SUPPORTED_CRED_PARAMS` as linted. + #[allow(clippy::unnecessary_to_owned)] let expected_cbor = cbor_map_options! { 0x01 => cbor_array_vec![vec![ #[cfg(feature = "with_ctap1")] diff --git a/src/env/tock/storage.rs b/src/env/tock/storage.rs index c0cacd7..aaf5763 100644 --- a/src/env/tock/storage.rs +++ b/src/env/tock/storage.rs @@ -261,7 +261,7 @@ impl TockUpgradeStorage { pub fn new() -> StorageResult { let mut locations = TockUpgradeStorage { page_size: get_info(command_nr::get_info_nr::PAGE_SIZE, 0)?, - partition: Partition::new(), + partition: Partition::default(), metadata: ModRange::new_empty(), running_metadata: ModRange::new_empty(), identifier: Self::PARTITION_ADDRESS_A as u32,