diff --git a/src/app_ui/sign/nep413/payload.rs b/src/app_ui/sign/nep413/payload.rs index a0bc517..b1836d2 100644 --- a/src/app_ui/sign/nep413/payload.rs +++ b/src/app_ui/sign/nep413/payload.rs @@ -38,7 +38,7 @@ fn format<'b, 'a: 'b>( writer.push_fields(message_fields).unwrap(); // 3 - hex::encode_to_slice(&payload.nonce, &mut field_context.nonce_buffer).unwrap(); + hex::encode_to_slice(payload.nonce, &mut field_context.nonce_buffer).unwrap(); writer .push_fields(ElipsisFields::one(Field { name: "Nonce", diff --git a/src/handlers/common/action/delegate.rs b/src/handlers/common/action/delegate.rs index 188ae0a..7365168 100644 --- a/src/handlers/common/action/delegate.rs +++ b/src/handlers/common/action/delegate.rs @@ -16,16 +16,10 @@ pub fn handle( stream.reader.comm.reply(AppSW::TxParsingFail); sign_ui::widgets::delegate_error_screen(); loop { - match stream.reader.comm.next_event::() { - Event::Button(button) => match button { - ButtonEvent::BothButtonsRelease => { - return Err(AppSW::TxParsingFail); - } - _ => { - // ignore all other button presses - } - }, - _ => (), + if let Event::Button(ButtonEvent::BothButtonsRelease) = + stream.reader.comm.next_event::() + { + return Err(AppSW::TxParsingFail); }; } } diff --git a/src/handlers/common/action/function_call.rs b/src/handlers/common/action/function_call.rs index c955643..d997db1 100644 --- a/src/handlers/common/action/function_call.rs +++ b/src/handlers/common/action/function_call.rs @@ -70,14 +70,12 @@ fn handle_common( .map_err(|_err| AppSW::TxParsingFail)?; match representation { ArgsRepr::BinHex(args_bin) => { - if !sign_ui::action::ui_display_function_call_bin(&func_call_common, &args_bin, params) - { + if !sign_ui::action::ui_display_function_call_bin(&func_call_common, args_bin, params) { return Err(AppSW::Deny); } } ArgsRepr::String(args_str) => { - if !sign_ui::action::ui_display_function_call_str(&func_call_common, &args_str, params) - { + if !sign_ui::action::ui_display_function_call_str(&func_call_common, args_str, params) { return Err(AppSW::Deny); } } diff --git a/src/handlers/get_public_key.rs b/src/handlers/get_public_key.rs index 5f5070e..a3946f3 100644 --- a/src/handlers/get_public_key.rs +++ b/src/handlers/get_public_key.rs @@ -36,10 +36,8 @@ pub fn handler(comm: &mut Comm, display: bool) -> Result<(), AppSW> { #[cfg(feature = "speculos")] pk.debug_print()?; - if display { - if !address::ui_display_pk_base58(&pk)? { - return Err(AppSW::Deny); - } + if display && !address::ui_display_pk_base58(&pk)? { + return Err(AppSW::Deny); } comm.append(&pk.0); diff --git a/src/io/mod.rs b/src/io/mod.rs index 56b9dfc..f27ffd6 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -226,7 +226,7 @@ fn _assert_error_is_sync_send() { /// A trait for objects which are byte-oriented sinks. /// -/// Implementors of the `Write` trait are sometimes called 'writers'. +/// Implementers of the `Write` trait are sometimes called 'writers'. /// /// Writers are defined by two required methods, [`write`] and [`flush`]: /// @@ -237,7 +237,7 @@ fn _assert_error_is_sync_send() { /// themselves for ensuring that all buffered data has been pushed out to the /// 'true sink'. /// -/// Writers are intended to be composable with one another. Many implementors +/// Writers are intended to be composable with one another. Many implementers /// throughout [`std::io`] take and provide types which implement the `Write` /// trait. /// @@ -509,6 +509,7 @@ impl Write for &mut W { /// /// Note that writing updates the slice to point to the yet unwritten part. /// The slice will be empty when it has been completely overwritten. +#[allow(clippy::mem_replace_with_default)] impl Write for &mut [u8] { fn write(&mut self, data: &[u8]) -> Result { let amt = core::cmp::min(data.len(), self.len()); @@ -533,15 +534,15 @@ impl Write for &mut [u8] { /// The `Read` trait allows for reading bytes from a source. /// -/// Implementors of the `Read` trait are called 'readers'. +/// Implementers of the `Read` trait are called 'readers'. /// /// Readers are defined by one required method, [`read()`]. Each call to [`read()`] /// will attempt to pull bytes from this source into a provided buffer. A /// number of other methods are implemented in terms of [`read()`], giving -/// implementors a number of ways to read bytes while only needing to implement +/// implementers a number of ways to read bytes while only needing to implement /// a single method. /// -/// Readers are intended to be composable with one another. Many implementors +/// Readers are intended to be composable with one another. Many implementers /// throughout [`std::io`] take and provide types which implement the `Read` /// trait. /// diff --git a/src/main.rs b/src/main.rs index 416eb81..0c4ecd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ #![no_std] #![no_main] +#![allow(clippy::new_without_default)] mod utils { pub mod crypto { diff --git a/src/parsing/borsh/mod.rs b/src/parsing/borsh/mod.rs index e9635d6..379209c 100644 --- a/src/parsing/borsh/mod.rs +++ b/src/parsing/borsh/mod.rs @@ -71,7 +71,7 @@ impl BorshDeserialize for u32 { reader .read_exact(&mut buf) .map_err(unexpected_eof_to_unexpected_length_of_input)?; - let res = u32::from_le_bytes(buf.try_into().unwrap()); + let res = u32::from_le_bytes(buf); Ok(res) } } @@ -82,7 +82,7 @@ impl BorshDeserialize for u64 { reader .read_exact(&mut buf) .map_err(unexpected_eof_to_unexpected_length_of_input)?; - let res = u64::from_le_bytes(buf.try_into().unwrap()); + let res = u64::from_le_bytes(buf); Ok(res) } } @@ -93,7 +93,7 @@ impl BorshDeserialize for u128 { reader .read_exact(&mut buf) .map_err(unexpected_eof_to_unexpected_length_of_input)?; - let res = u128::from_le_bytes(buf.try_into().unwrap()); + let res = u128::from_le_bytes(buf); Ok(res) } } diff --git a/src/parsing/transaction_stream_reader/mod.rs b/src/parsing/transaction_stream_reader/mod.rs index 102d502..bcb924d 100644 --- a/src/parsing/transaction_stream_reader/mod.rs +++ b/src/parsing/transaction_stream_reader/mod.rs @@ -88,7 +88,7 @@ impl HashingStream { impl io::Read for HashingStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { - if buf.len() > 0 { + if !buf.is_empty() { let n = self.reader.read(buf)?; // update hash on each chunk passing through @@ -137,14 +137,9 @@ impl<'a> SingleTxStream<'a> { fn get_next_chunk(&mut self) -> io::Result<&[u8]> { let is_last_chunk = loop { match self.comm.next_event() { - Event::Button(button) => match button { - ButtonEvent::BothButtonsRelease => { - return Err(io::Error::from(io::ErrorKind::Interrupted)) - } - _ => { - // ignore all other button presses - } - }, + Event::Button(ButtonEvent::BothButtonsRelease) => { + return Err(io::Error::from(io::ErrorKind::Interrupted)) + } Event::Command(Instruction::GetVersion) | Event::Command(Instruction::GetPubkey { .. }) => { return Err(io::Error::from(io::ErrorKind::InvalidData)) @@ -197,6 +192,6 @@ impl<'a> io::Read for SingleTxStream<'a> { let mut data = self.get_next_chunk()?; let n = data.read(buf)?; self.chunk_counter += n; - return Ok(n); + Ok(n) } } diff --git a/src/parsing/types/common/action/add_key.rs b/src/parsing/types/common/action/add_key.rs index 870df91..a026e60 100644 --- a/src/parsing/types/common/action/add_key.rs +++ b/src/parsing/types/common/action/add_key.rs @@ -42,7 +42,7 @@ pub struct FunctionCallPermission { // This isn't an AccountId because already existing records in testnet genesis have invalid // values for this field (see: https://github.com/near/nearcore/pull/4621#issuecomment-892099860) - // we accomodate those by using a string, allowing us to read and parse genesis. + // we accommodate those by using a string, allowing us to read and parse genesis. /// The access key only allows transactions with the given receiver's account id. pub receiver_id: CappedString<64>, diff --git a/src/parsing/types/common/action/mod.rs b/src/parsing/types/common/action/mod.rs index dd7594f..7c19249 100644 --- a/src/parsing/types/common/action/mod.rs +++ b/src/parsing/types/common/action/mod.rs @@ -51,9 +51,7 @@ impl BorshDeserialize for Action { 6 => Ok(Self::DeleteKey), 7 => Ok(Self::DeleteAccount), 8 => Ok(Self::Delegate), - _ => { - return Err(Error::from(ErrorKind::InvalidData)); - } + _ => Err(Error::from(ErrorKind::InvalidData)), } } } diff --git a/src/parsing/types/transaction/prefix/mod.rs b/src/parsing/types/transaction/prefix/mod.rs index 2389bcd..f00e2ad 100644 --- a/src/parsing/types/transaction/prefix/mod.rs +++ b/src/parsing/types/transaction/prefix/mod.rs @@ -43,8 +43,7 @@ impl Prefix { drop(nonce); self.receiver_id.deserialize_reader_in_place(reader)?; - let crypto_hash: CryptoHash = BorshDeserialize::deserialize_reader(reader)?; - drop(crypto_hash); + let _crypto_hash: CryptoHash = BorshDeserialize::deserialize_reader(reader)?; let number_of_actions: u32 = BorshDeserialize::deserialize_reader(reader)?; self.number_of_actions = number_of_actions; diff --git a/src/utils/crypto/public_key.rs b/src/utils/crypto/public_key.rs index ca8e773..4f3d7ff 100644 --- a/src/utils/crypto/public_key.rs +++ b/src/utils/crypto/public_key.rs @@ -55,8 +55,9 @@ impl PublicKeyBe { let mut out = [0u8; PUBLIC_KEY_BIG_ENDIAN_LEN]; // copy public key little endian to big endian - for i in 0..PUBLIC_KEY_BIG_ENDIAN_LEN { - out[i] = input.pubkey[PUBLIC_KEY_LITTLE_ENDIAN_LEN - 1 - i]; + + for (i, out_byte) in out.iter_mut().enumerate().take(PUBLIC_KEY_BIG_ENDIAN_LEN) { + *out_byte = input.pubkey[PUBLIC_KEY_LITTLE_ENDIAN_LEN - 1 - i]; } // set sign bit if (input.pubkey[PUBLIC_KEY_BIG_ENDIAN_LEN] & 1) != 0 { @@ -78,8 +79,8 @@ impl PublicKeyBe { Ok(()) } - pub fn display_str_hex<'a, 'b>(&'a self, buffer: &'b mut [u8; 64]) -> &'b str { - hex::encode_to_slice(&self.0, buffer).unwrap(); + pub fn display_str_hex<'b>(&self, buffer: &'b mut [u8; 64]) -> &'b str { + hex::encode_to_slice(self.0, buffer).unwrap(); core::str::from_utf8(buffer).unwrap() } diff --git a/src/utils/types/hex_display.rs b/src/utils/types/hex_display.rs index 199582e..8faf516 100644 --- a/src/utils/types/hex_display.rs +++ b/src/utils/types/hex_display.rs @@ -53,7 +53,7 @@ impl HexDisplay { for ind in (0..self.used).rev() { let char_range = ind * 2..=ind * 2 + 1; tmp_buffer.copy_from_slice(&self.buffer[ind..ind + 1]); - hex::encode_to_slice(&tmp_buffer, &mut self.buffer[char_range]).unwrap(); + hex::encode_to_slice(tmp_buffer, &mut self.buffer[char_range]).unwrap(); } }