diff --git a/src/app_ui/address.rs b/src/app_ui/address.rs index 1534985..933ffd4 100644 --- a/src/app_ui/address.rs +++ b/src/app_ui/address.rs @@ -26,17 +26,13 @@ use nanos_ui::ui::{Field, MultiFieldReview}; const DISPLAY_ADDR_BYTES_LEN: usize = 20; pub fn ui_display_pk(addr: &[u8]) -> Result { - let addr_hex_str_buf = - to_hex_all_caps(&addr[addr.len() - DISPLAY_ADDR_BYTES_LEN as usize..]) - .map_err(|_| Reply(SW_DISPLAY_ADDRESS_FAIL))?; + let addr_hex_str_buf = to_hex_all_caps(&addr[addr.len() - DISPLAY_ADDR_BYTES_LEN as usize..]) + .map_err(|_| Reply(SW_DISPLAY_ADDRESS_FAIL))?; let addr_hex_str = from_utf8(&addr_hex_str_buf[..DISPLAY_ADDR_BYTES_LEN * 2]) .map_err(|_| Reply(SW_DISPLAY_ADDRESS_FAIL))?; let mut addr_hex_str_with_prefix_buf = [0u8; DISPLAY_ADDR_BYTES_LEN * 2 + 2]; - concatenate( - &["0x", &addr_hex_str], - &mut addr_hex_str_with_prefix_buf, - ); + concatenate(&["0x", &addr_hex_str], &mut addr_hex_str_with_prefix_buf); let addr_hex_str_with_prefix = from_utf8(&addr_hex_str_with_prefix_buf).map_err(|_| Reply(SW_DISPLAY_ADDRESS_FAIL))?; diff --git a/src/app_ui/sign.rs b/src/app_ui/sign.rs index 758f623..e3a8d4f 100644 --- a/src/app_ui/sign.rs +++ b/src/app_ui/sign.rs @@ -46,7 +46,8 @@ pub fn ui_display_tx(tx: &Tx) -> Result { from_utf8(&addr_with_prefix_buf).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; // Format memo - let memo_str = from_utf8(&tx.memo[..tx.memo_len as usize]).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; + let memo_str = + from_utf8(&tx.memo[..tx.memo_len as usize]).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; // Define transaction review fields let my_fields = [ diff --git a/src/handlers/sign_tx.rs b/src/handlers/sign_tx.rs index d9ff288..2846121 100644 --- a/src/handlers/sign_tx.rs +++ b/src/handlers/sign_tx.rs @@ -15,7 +15,7 @@ * limitations under the License. *****************************************************************************/ use crate::app_ui::sign::ui_display_tx; -use crate::utils::{read_bip32_path, varint_read, slice_or_err, MAX_ALLOWED_PATH_LEN}; +use crate::utils::{read_bip32_path, slice_or_err, varint_read, MAX_ALLOWED_PATH_LEN}; use crate::{SW_DENY, SW_TX_HASH_FAIL, SW_TX_PARSING_FAIL, SW_TX_SIGN_FAIL, SW_WRONG_TX_LENGTH}; use nanos_sdk::bindings::{ cx_hash_no_throw, cx_hash_t, cx_keccak_init_no_throw, cx_sha3_t, CX_LAST, CX_OK, @@ -50,15 +50,15 @@ impl<'a> TryFrom<&'a [u8]> for Tx<'a> { let value = u64::from_be_bytes(slice_or_err(raw_tx, 28, 8)?.try_into().map_err(|_| ())?); // Memo length let (memo_len_u64, memo_len_size) = varint_read(&raw_tx[36..])?; - let memo_len = memo_len_u64 as usize; + let memo_len = memo_len_u64 as usize; // Memo let memo = slice_or_err(raw_tx, 36 + memo_len_size, memo_len)?; - + // Check memo ASCII encoding if !memo[..memo_len].iter().all(|&byte| byte.is_ascii()) { return Err(()); } - + Ok(Tx { nonce, value, @@ -148,7 +148,7 @@ fn compute_signature_and_append(comm: &mut Comm, ctx: &mut TxContext) -> Result< let mut message_hash: [u8; 32] = [0u8; 32]; unsafe { - if cx_keccak_init_no_throw(&mut keccak256, 256) != CX_OK { + if cx_keccak_init_no_throw(&mut keccak256, 256) != CX_OK { return Err(Reply(SW_TX_HASH_FAIL)); } if cx_hash_no_throw( diff --git a/src/utils.rs b/src/utils.rs index ee44916..366d650 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -96,14 +96,14 @@ pub fn slice_or_err(slice: &[u8], start: usize, len: usize) -> Result<&[u8], ()> } /// Read a varint from a slice -pub fn varint_read(input: &[u8]) -> Result<(u64, usize), ()> { +pub fn varint_read(input: &[u8]) -> Result<(u64, usize), ()> { let mut bytes = [0u8; 8]; let int_length: usize; if input.is_empty() { return Err(()); } - + let prefix = input[0]; if prefix == 0xFD { @@ -122,11 +122,11 @@ pub fn varint_read(input: &[u8]) -> Result<(u64, usize), ()> { } int_length = 8; } else { - return Ok((u64::from(prefix), 1)); + return Ok((u64::from(prefix), 1)); } let buf = slice_or_err(input, 1, int_length)?; bytes[..int_length].copy_from_slice(buf); let result = u64::from_le_bytes(bytes); Ok((result, int_length + 1)) -} \ No newline at end of file +}