Skip to content

Commit

Permalink
commands: Python 3 fix: properly distinguish str and list
Browse files Browse the repository at this point in the history
Unlike Python 2, in Python 3 strings also have attribute '__iter__'.
Because of that, a string could be passed to select_file(), that
actually expects a list as the first parameter.

P.S. Madness, Python 3 is just a new different language...
P.P.S. They should have renamed it not to confuse people.

Change-Id: I92af47abb6adff0271c55e7f278e8c5188f2be75
Fixes: OS#4419
  • Loading branch information
axilirator committed Feb 26, 2020
1 parent fa617ac commit edf873d
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pySim/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def sel_ctrl(self, value):

def select_file(self, dir_list):
rv = []
if type(dir_list) is not list:
dir_list = [dir_list]
for i in dir_list:
data, sw = self._tp.send_apdu_checksw(self.cla_byte + "a4" + self.sel_ctrl + "02" + i)
rv.append(data)
Expand All @@ -112,8 +114,6 @@ def select_adf(self, aid):
return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid)

def read_binary(self, ef, length=None, offset=0):
if not hasattr(type(ef), '__iter__'):
ef = [ef]
r = self.select_file(ef)
if len(r[-1]) == 0:
return (None, None)
Expand All @@ -123,23 +123,17 @@ def read_binary(self, ef, length=None, offset=0):
return self._tp.send_apdu(pdu)

def update_binary(self, ef, data, offset=0):
if not hasattr(type(ef), '__iter__'):
ef = [ef]
self.select_file(ef)
pdu = self.cla_byte + 'd6%04x%02x' % (offset, len(data) // 2) + data
return self._tp.send_apdu_checksw(pdu)

def read_record(self, ef, rec_no):
if not hasattr(type(ef), '__iter__'):
ef = [ef]
r = self.select_file(ef)
rec_length = self.__record_len(r)
pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length)
return self._tp.send_apdu(pdu)

def update_record(self, ef, rec_no, data, force_len=False):
if not hasattr(type(ef), '__iter__'):
ef = [ef]
r = self.select_file(ef)
if not force_len:
rec_length = self.__record_len(r)
Expand Down

0 comments on commit edf873d

Please sign in to comment.