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

Commit

Permalink
Merge pull request #22 from dj8yfo/ci_clippy_spell
Browse files Browse the repository at this point in the history
ci: fix spelling + clippy
  • Loading branch information
dj8yfo authored Feb 9, 2024
2 parents c83c646 + f977442 commit 0994a3c
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 48 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
11 changes: 6 additions & 5 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]:
///
Expand All @@ -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.
///
Expand Down 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 All @@ -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.
///
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)
}
}
2 changes: 1 addition & 1 deletion src/parsing/types/common/action/add_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand Down
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 0994a3c

Please sign in to comment.