Tweak Le appropriately depending on its swize

This commit is contained in:
Kamran Khan
2020-12-03 08:10:44 -08:00
parent cc8bdb982d
commit bec94f02be

View File

@@ -192,12 +192,27 @@ impl TryFrom<&[u8]> for APDU {
last_byte last_byte
} }
} }
2 => BigEndian::read_u16( 2 => {
&payload[payload.len() - extended_apdu_le_len..], let le_parsed = BigEndian::read_u16(&payload[payload.len() - 2..]);
) as u32, if le_parsed == 0x00 {
3 => BigEndian::read_u32( 0x100
&payload[payload.len() - extended_apdu_le_len..], } else {
), le_parsed as u32
}
}
3 => {
let le_first_byte: u32 =
(*payload.get(payload.len() - 3).unwrap()).into();
if le_first_byte != 0x00 {
return Err(ApduStatusCode::SW_INTERNAL_EXCEPTION);
}
let le_parsed = BigEndian::read_u16(&payload[payload.len() - 2..]);
if le_parsed == 0x00 {
0x10000
} else {
le_parsed as u32
}
}
_ => return Err(ApduStatusCode::SW_INTERNAL_EXCEPTION), _ => return Err(ApduStatusCode::SW_INTERNAL_EXCEPTION),
}, },
case_type: ApduType::Extended(match extended_apdu_le_len { case_type: ApduType::Extended(match extended_apdu_le_len {
@@ -381,7 +396,7 @@ mod test {
}, },
lc: 0xb1, lc: 0xb1,
data: payload.to_vec(), data: payload.to_vec(),
le: 0x00, le: 0x100,
case_type: ApduType::Extended(Case::Lc3DataLe2), case_type: ApduType::Extended(Case::Lc3DataLe2),
}; };
assert_eq!(Ok(expected), response); assert_eq!(Ok(expected), response);
@@ -408,7 +423,7 @@ mod test {
}, },
lc: 0x40, lc: 0x40,
data: payload.to_vec(), data: payload.to_vec(),
le: 0x00, le: 0x100,
case_type: ApduType::Extended(Case::Lc3DataLe2), case_type: ApduType::Extended(Case::Lc3DataLe2),
}; };
assert_eq!(Ok(expected), response); assert_eq!(Ok(expected), response);