From 162c00a0d12e5c92bd08ff180d365c57568476b3 Mon Sep 17 00:00:00 2001 From: Kamran Khan Date: Thu, 10 Dec 2020 19:54:25 -0800 Subject: [PATCH] Simplify Le length calculation --- src/ctap/apdu.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ctap/apdu.rs b/src/ctap/apdu.rs index 7136084..3bf83da 100644 --- a/src/ctap/apdu.rs +++ b/src/ctap/apdu.rs @@ -173,14 +173,10 @@ impl TryFrom<&[u8]> for APDU { 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 = match possible_le_len { - // 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), - }; + let extended_apdu_le_len: usize = payload.len() - extended_apdu_lc - 3; + if extended_apdu_le_len > 3 { + return Err(ApduStatusCode::SW_WRONG_LENGTH); + } 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