De-deuplicate le length calculation

This commit is contained in:
Kamran Khan
2020-12-09 20:43:06 -08:00
parent 56bc86c5d0
commit 0da13cd61f

View File

@@ -172,9 +172,12 @@ impl TryFrom<&[u8]> for APDU {
if payload.len() < extended_apdu_lc + 3 { if payload.len() < extended_apdu_lc + 3 {
return Err(ApduStatusCode::SW_WRONG_LENGTH); return Err(ApduStatusCode::SW_WRONG_LENGTH);
} }
let extended_apdu_le_len: usize = match payload.len() - extended_apdu_lc - 3 {
let possible_le_len = payload.len() as i32 - extended_apdu_lc as i32 - 3;
let extended_apdu_le_len: usize = match possible_le_len {
// There's some possible Le bytes at the end // There's some possible Le bytes at the end
0..=3 => payload.len() - extended_apdu_lc - 3, 0..=3 => possible_le_len as usize,
// There are more bytes than even Le3 can consume, return an error // There are more bytes than even Le3 can consume, return an error
_ => return Err(ApduStatusCode::SW_WRONG_LENGTH), _ => return Err(ApduStatusCode::SW_WRONG_LENGTH),
}; };