Skip to content

Commit

Permalink
Minor code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
kingofpayne committed Dec 29, 2023
1 parent 255663c commit d2b5ce3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ impl<const S: usize> TryFrom<&[u8]> for Bip32Path<S> {
///
/// * `data` - Encoded BIP32 path. First byte is the length of the path, as encoded by ragger.
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
let input_path_len = (data.len() - 1) / 4;
// Check data length
if data.is_empty() // At least the length byte is required
|| ((data.len() - 1) / 4 > S)
|| (input_path_len > S)
|| (data[0] as usize * 4 != data.len() - 1)
{
return Err(AppSW::WrongApduLength);
Expand All @@ -55,7 +56,7 @@ impl<const S: usize> TryFrom<&[u8]> for Bip32Path<S> {

Ok(Self {
buffer: path,
len: (data.len() - 1) / 4,
len: input_path_len,
})
}
}
Expand Down

0 comments on commit d2b5ce3

Please sign in to comment.