From 729f4a9119d5d82e822f3c50a9212e266ec27e3c Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 20 Feb 2023 10:52:49 +0100 Subject: [PATCH 1/2] Allow a 4-byte APDU. Should fix #7. --- smartleia/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smartleia/__init__.py b/smartleia/__init__.py index ce2163e..3ad2949 100644 --- a/smartleia/__init__.py +++ b/smartleia/__init__.py @@ -476,13 +476,13 @@ def create_APDU_from_bytes(_bytes) -> APDU: apdu.cla, apdu.ins, apdu.p1, apdu.p2 = _bytes[:4] apdu.send_le = 0 - if len(_bytes) < 5: - raise NotImplementedError( - "Error in decoding APDU buffer of size %d is too small" % (len(_bytes)) - ) if len(_bytes) == 5: apdu.lc, apdu.le = 0, _bytes[4] apdu.send_le = 1 + elif len(_bytes) == 4: + # send_le = 0 and the below give a short 4-byte APDU + apdu.lc = 0 + apdu.le = 0 else: apdu.lc, apdu.le = _bytes[4], 0 if apdu.lc == 0x00 and len(_bytes) >= 8: From 52baba0dd61b38827204c80a300b07f344c37764 Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 24 Jul 2023 17:44:44 +0200 Subject: [PATCH 2/2] Raise for too small APDU (<4 bytes). --- smartleia/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/smartleia/__init__.py b/smartleia/__init__.py index 3ad2949..d8d9a40 100644 --- a/smartleia/__init__.py +++ b/smartleia/__init__.py @@ -483,6 +483,10 @@ def create_APDU_from_bytes(_bytes) -> APDU: # send_le = 0 and the below give a short 4-byte APDU apdu.lc = 0 apdu.le = 0 + elif len(_bytes) < 4: + raise NotImplementedError( + "Error in decoding APDU buffer of size %d is too small" % (len(_bytes)) + ) else: apdu.lc, apdu.le = _bytes[4], 0 if apdu.lc == 0x00 and len(_bytes) >= 8: