Skip to content

Commit

Permalink
Merge pull request #8 from J08nY/fix/APDU-4bytes
Browse files Browse the repository at this point in the history
Allow a 4-byte APDU.
  • Loading branch information
rben-dev committed Jul 24, 2023
2 parents fecf456 + 52baba0 commit ffdefa0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions smartleia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,17 @@ 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
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:
Expand Down

0 comments on commit ffdefa0

Please sign in to comment.