mirror of https://gerrit.osmocom.org/pysim
__init__: allow wildcards in expected SW for send_apdu_checksw()
The method send_apdu_checksw() is used to check the SW of the final response against some pre defined value. However, in many cases the last two digits of the SW are used to return varying information (e.g. length information or a more specific status info). To cover those cases it would be helfpul to define status words that contain wildcards (e.g. 61**) in order to be able to accept all SWs from 6100 to 61ff. - When the user supplies an expected SW with wildcards, mask out those digits in the response before comparing Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7
This commit is contained in:
parent
d9824887c9
commit
d4ebb6fdf4
|
@ -77,12 +77,23 @@ class LinkBase(object):
|
|||
"""send_apdu_checksw(pdu,sw): Sends an APDU and check returned SW
|
||||
|
||||
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
|
||||
sw : string of 4 hexadecimal characters (ex. "9000")
|
||||
sw : string of 4 hexadecimal characters (ex. "9000"). The
|
||||
user may mask out certain digits using a '?' to add some
|
||||
ambiguity if needed.
|
||||
return : tuple(data, sw), where
|
||||
data : string (in hex) of returned data (ex. "074F4EFFFF")
|
||||
sw : string (in hex) of status word (ex. "9000")
|
||||
"""
|
||||
rv = self.send_apdu(pdu)
|
||||
if sw.lower() != rv[1]:
|
||||
|
||||
# Create a masked version of the returned status word
|
||||
sw_masked = ""
|
||||
for i in range(0, 4):
|
||||
if sw.lower()[i] == '?':
|
||||
sw_masked = sw_masked + '?'
|
||||
else:
|
||||
sw_masked = sw_masked + rv[1][i].lower()
|
||||
|
||||
if sw.lower() != sw_masked:
|
||||
raise RuntimeError("SW match failed ! Expected %s and got %s." % (sw.lower(), rv[1]))
|
||||
return rv
|
||||
|
|
Loading…
Reference in New Issue