From 5511811703ba6346a929998879ca5b5cc217d0cf Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Wed, 23 Sep 2020 16:21:20 +0200 Subject: [PATCH] Fix most Clippy warnings. --- libraries/crypto/src/ec/int256.rs | 5 +++++ src/ctap/command.rs | 2 +- src/ctap/mod.rs | 2 +- src/ctap/storage.rs | 6 ++++-- third_party/lang-items/src/allocator.rs | 1 + third_party/libtock-drivers/src/console.rs | 1 + third_party/libtock-drivers/src/rng.rs | 2 +- third_party/libtock-drivers/src/usb_ctap_hid.rs | 2 ++ 8 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libraries/crypto/src/ec/int256.rs b/libraries/crypto/src/ec/int256.rs index a3f572c..9954c37 100644 --- a/libraries/crypto/src/ec/int256.rs +++ b/libraries/crypto/src/ec/int256.rs @@ -554,6 +554,7 @@ impl Add for &Int256 { type Output = (Int256, Digit); // Returns sum and carry (0 or 1). + #[allow(clippy::suspicious_arithmetic_impl)] fn add(self, other: &Int256) -> (Int256, Digit) { let mut digits = [0; NDIGITS]; let mut carry: DoubleDigit = 0; @@ -570,6 +571,7 @@ impl Add for &Int256 { impl AddAssign<&Int256> for Int256 { // Adds to self, ignoring carry. + #[allow(clippy::suspicious_op_assign_impl)] fn add_assign(&mut self, other: &Int256) { let mut carry: DoubleDigit = 0; for i in 0..NDIGITS { @@ -584,6 +586,7 @@ impl Add for &Int256 { type Output = (Int256, Digit); // Returns sum and carry (0 or 1). + #[allow(clippy::suspicious_arithmetic_impl)] fn add(self, digit: Digit) -> (Int256, Digit) { let mut digits = [0; NDIGITS]; let mut carry = digit as DoubleDigit; @@ -603,6 +606,7 @@ impl Sub for &Int256 { type Output = (Int256, Digit); // Returns difference and borrow (0 or -1). + #[allow(clippy::suspicious_arithmetic_impl)] fn sub(self, other: &Int256) -> (Int256, Digit) { let mut digits = [0; NDIGITS]; let mut borrow: SignedDoubleDigit = 0; @@ -620,6 +624,7 @@ impl Sub for &Int256 { impl SubAssign<&Int256> for Int256 { // Substract from self, ignoring carry. + #[allow(clippy::suspicious_op_assign_impl)] fn sub_assign(&mut self, other: &Int256) { let mut borrow: SignedDoubleDigit = 0; for i in 0..NDIGITS { diff --git a/src/ctap/command.rs b/src/ctap/command.rs index d76a8b7..0c5ce15 100644 --- a/src/ctap/command.rs +++ b/src/ctap/command.rs @@ -325,7 +325,7 @@ impl TryFrom for AuthenticatorClientPinParameters { let key_agreement = key_agreement .map(extract_map) .transpose()? - .map(|x| CoseKey(x)); + .map(CoseKey); let pin_auth = pin_auth.map(extract_byte_string).transpose()?; let new_pin_enc = new_pin_enc.map(extract_byte_string).transpose()?; let pin_hash_enc = pin_hash_enc.map(extract_byte_string).transpose()?; diff --git a/src/ctap/mod.rs b/src/ctap/mod.rs index 5b78851..1cbb884 100644 --- a/src/ctap/mod.rs +++ b/src/ctap/mod.rs @@ -694,7 +694,7 @@ where key_id: credential.credential_id.clone(), transports: None, // You can set USB as a hint here. }; - let user = if (flags & UV_FLAG != 0) && (credential.user_handle.len() > 0) { + let user = if (flags & UV_FLAG != 0) && !credential.user_handle.is_empty() { Some(PublicKeyCredentialUserEntity { user_id: credential.user_handle.clone(), user_name: None, diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index 411f8ae..00217e7 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -88,6 +88,7 @@ const _DEFAULT_MIN_PIN_LENGTH_RP_IDS: Vec = Vec::new(); #[cfg(feature = "with_ctap2_1")] const _MAX_RP_IDS_LENGTH: usize = 8; +#[allow(clippy::enum_variant_names)] #[derive(PartialEq, Eq, PartialOrd, Ord)] enum Key { // TODO(cretin): Test whether this doesn't consume too much memory. Otherwise, we can use less @@ -406,10 +407,11 @@ impl PersistentStore { data: pin_hash, sensitive: true, }; - Ok(match self.store.find_one(&Key::PinHash) { + match self.store.find_one(&Key::PinHash) { None => self.store.insert(entry)?, Some((index, _)) => self.store.replace(index, entry)?, - }) + } + Ok(()) } pub fn pin_retries(&self) -> Result { diff --git a/third_party/lang-items/src/allocator.rs b/third_party/lang-items/src/allocator.rs index d0a02ec..0d1de00 100644 --- a/third_party/lang-items/src/allocator.rs +++ b/third_party/lang-items/src/allocator.rs @@ -44,6 +44,7 @@ impl TockAllocator { } unsafe impl GlobalAlloc for TockAllocator { + #[allow(clippy::let_and_return)] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { let ptr = HEAP .allocate_first_fit(layout) diff --git a/third_party/libtock-drivers/src/console.rs b/third_party/libtock-drivers/src/console.rs index 4784a42..4b7ff02 100644 --- a/third_party/libtock-drivers/src/console.rs +++ b/third_party/libtock-drivers/src/console.rs @@ -25,6 +25,7 @@ pub struct Console { } impl Console { + #[allow(clippy::new_without_default)] pub fn new() -> Console { Console { allow_buffer: [0; BUFFER_SIZE], diff --git a/third_party/libtock-drivers/src/rng.rs b/third_party/libtock-drivers/src/rng.rs index 96ae953..4498e6a 100644 --- a/third_party/libtock-drivers/src/rng.rs +++ b/third_party/libtock-drivers/src/rng.rs @@ -41,5 +41,5 @@ pub fn fill_buffer(buf: &mut [u8]) -> bool { } util::yieldk_for(|| is_filled.get()); - return true; + true } diff --git a/third_party/libtock-drivers/src/usb_ctap_hid.rs b/third_party/libtock-drivers/src/usb_ctap_hid.rs index 14cec88..d585932 100644 --- a/third_party/libtock-drivers/src/usb_ctap_hid.rs +++ b/third_party/libtock-drivers/src/usb_ctap_hid.rs @@ -173,6 +173,7 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus { // Same as recv, but with a timeout. // If the timeout elapses, return None. +#[allow(clippy::let_and_return)] pub fn recv_with_timeout( buf: &mut [u8; 64], timeout_delay: Duration, @@ -199,6 +200,7 @@ pub fn recv_with_timeout( // Same as send_or_recv, but with a timeout. // If the timeout elapses, return None. +#[allow(clippy::let_and_return)] pub fn send_or_recv_with_timeout( buf: &mut [u8; 64], timeout_delay: Duration,