Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
ci: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Feb 9, 2024
1 parent 2b1bf84 commit f977442
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/app_ui/sign/nep413/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 4 additions & 10 deletions src/handlers/common/action/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Instruction>() {
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::<Instruction>()
{
return Err(AppSW::TxParsingFail);
};
}
}
6 changes: 2 additions & 4 deletions src/handlers/common/action/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/handlers/get_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ impl<W: Write + ?Sized> 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<usize> {
let amt = core::cmp::min(data.len(), self.len());
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#![no_std]
#![no_main]
#![allow(clippy::new_without_default)]

mod utils {
pub mod crypto {
Expand Down
6 changes: 3 additions & 3 deletions src/parsing/borsh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
15 changes: 5 additions & 10 deletions src/parsing/transaction_stream_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<R> HashingStream<R> {

impl<R: io::Read> io::Read for HashingStream<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if buf.len() > 0 {
if !buf.is_empty() {
let n = self.reader.read(buf)?;

// update hash on each chunk passing through
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
}
4 changes: 1 addition & 3 deletions src/parsing/types/common/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
3 changes: 1 addition & 2 deletions src/parsing/types/transaction/prefix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/utils/crypto/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/types/hex_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<const N: usize> HexDisplay<N> {
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();
}
}

Expand Down

0 comments on commit f977442

Please sign in to comment.