forked from public/pysim
move SW matching to a generic utility function
This will allow using it outside the transport/__init__.py Change-Id: Id26dfefa85d91e3b3a23e0049f3b833e29cb1cef
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pySim.exceptions import *
|
from pySim.exceptions import *
|
||||||
|
from pySim.utils import sw_match
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
|
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
|
||||||
@@ -93,14 +94,6 @@ class LinkBase(object):
|
|||||||
"""
|
"""
|
||||||
rv = self.send_apdu(pdu)
|
rv = self.send_apdu(pdu)
|
||||||
|
|
||||||
# Create a masked version of the returned status word
|
if not sw_match(rv[1], sw):
|
||||||
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 SwMatchError(rv[1], sw.lower())
|
raise SwMatchError(rv[1], sw.lower())
|
||||||
return rv
|
return rv
|
||||||
|
|||||||
@@ -759,3 +759,17 @@ def get_addr_type(addr):
|
|||||||
return 0x00
|
return 0x00
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def sw_match(sw, pattern):
|
||||||
|
"""Match given SW against given pattern."""
|
||||||
|
# Create a masked version of the returned status word
|
||||||
|
sw_lower = sw.lower()
|
||||||
|
sw_masked = ""
|
||||||
|
for i in range(0, 4):
|
||||||
|
if sw_lower[i] == '?':
|
||||||
|
sw_masked = sw_masked + '?'
|
||||||
|
elif sw_lower[i] == 'x':
|
||||||
|
sw_masked = sw_masked + 'x'
|
||||||
|
else:
|
||||||
|
sw_masked = sw_masked + sw_lower[i]
|
||||||
|
return sw_masked == pattern
|
||||||
|
|||||||
Reference in New Issue
Block a user