Simplify Le length calculation

This commit is contained in:
Kamran Khan
2020-12-10 19:54:25 -08:00
parent 6f1c63e9b8
commit 162c00a0d1

View File

@@ -173,14 +173,10 @@ impl TryFrom<&[u8]> for APDU {
return Err(ApduStatusCode::SW_WRONG_LENGTH); return Err(ApduStatusCode::SW_WRONG_LENGTH);
} }
let possible_le_len = payload.len() as i32 - extended_apdu_lc as i32 - 3; let extended_apdu_le_len: usize = payload.len() - extended_apdu_lc - 3;
if extended_apdu_le_len > 3 {
let extended_apdu_le_len: usize = match possible_le_len { return Err(ApduStatusCode::SW_WRONG_LENGTH);
// There's some possible Le bytes at the end }
0..=3 => possible_le_len as usize,
// There are more bytes than even Le3 can consume, return an error
_ => return Err(ApduStatusCode::SW_WRONG_LENGTH),
};
if byte_0 == 0 && extended_apdu_le_len <= 3 { if byte_0 == 0 && extended_apdu_le_len <= 3 {
// If first byte is zero AND the next two bytes can be parsed as a big-endian // If first byte is zero AND the next two bytes can be parsed as a big-endian