Skip to content

Commit c91085e

Browse files
committed
cosmetic: Switch to consistent four-spaces indent; run autopep8
We had a mixture of tab and 4space based indenting, which is a bad idea. 4space is the standard in python, so convert all our code to that. The result unfortuantely still shoed even more inconsistencies, so I've decided to run autopep8 on the entire code base. Change-Id: I4a4b1b444a2f43fab05fc5d2c8a7dd6ddecb5f07
1 parent 181c7c5 commit c91085e

29 files changed

+8183
-7231
lines changed

pySim-prog.py

+699-680
Large diffs are not rendered by default.

pySim-read.py

+314-304
Large diffs are not rendered by default.

pySim-shell.py

+824-761
Large diffs are not rendered by default.

pySim/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

pySim/ara_m.py

+65-17
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,35 @@
3434

3535
# various BER-TLV encoded Data Objects (DOs)
3636

37+
3738
class AidRefDO(BER_TLV_IE, tag=0x4f):
3839
# SEID v1.1 Table 6-3
3940
_construct = HexAdapter(GreedyBytes)
4041

42+
4143
class AidRefEmptyDO(BER_TLV_IE, tag=0xc0):
4244
# SEID v1.1 Table 6-3
4345
pass
4446

47+
4548
class DevAppIdRefDO(BER_TLV_IE, tag=0xc1):
4649
# SEID v1.1 Table 6-4
4750
_construct = HexAdapter(GreedyBytes)
4851

52+
4953
class PkgRefDO(BER_TLV_IE, tag=0xca):
5054
# Android UICC Carrier Privileges specific extension, see https://source.android.com/devices/tech/config/uicc
5155
_construct = Struct('package_name_string'/GreedyString("ascii"))
5256

53-
class RefDO(BER_TLV_IE, tag=0xe1, nested=[AidRefDO,AidRefEmptyDO,DevAppIdRefDO,PkgRefDO]):
57+
58+
class RefDO(BER_TLV_IE, tag=0xe1, nested=[AidRefDO, AidRefEmptyDO, DevAppIdRefDO, PkgRefDO]):
5459
# SEID v1.1 Table 6-5
5560
pass
5661

62+
5763
class ApduArDO(BER_TLV_IE, tag=0xd0):
5864
# SEID v1.1 Table 6-8
59-
def _from_bytes(self, do:bytes):
65+
def _from_bytes(self, do: bytes):
6066
if len(do) == 1:
6167
if do[0] == 0x00:
6268
self.decoded = {'generic_access_rule': 'never'}
@@ -76,6 +82,7 @@ def _from_bytes(self, do:bytes):
7682
'mask': b2h(do[offset+4:offset+8])}
7783
self.decoded = res
7884
return res
85+
7986
def _to_bytes(self):
8087
if 'generic_access_rule' in self.decoded:
8188
if self.decoded['generic_access_rule'] == 'never':
@@ -99,94 +106,118 @@ def _to_bytes(self):
99106
res += header_b + mask_b
100107
return res
101108

109+
102110
class NfcArDO(BER_TLV_IE, tag=0xd1):
103111
# SEID v1.1 Table 6-9
104-
_construct = Struct('nfc_event_access_rule'/Enum(Int8ub, never=0, always=1))
112+
_construct = Struct('nfc_event_access_rule' /
113+
Enum(Int8ub, never=0, always=1))
114+
105115

106116
class PermArDO(BER_TLV_IE, tag=0xdb):
107117
# Android UICC Carrier Privileges specific extension, see https://source.android.com/devices/tech/config/uicc
108118
_construct = Struct('permissions'/HexAdapter(Bytes(8)))
109119

120+
110121
class ArDO(BER_TLV_IE, tag=0xe3, nested=[ApduArDO, NfcArDO, PermArDO]):
111122
# SEID v1.1 Table 6-7
112123
pass
113124

125+
114126
class RefArDO(BER_TLV_IE, tag=0xe2, nested=[RefDO, ArDO]):
115127
# SEID v1.1 Table 6-6
116128
pass
117129

130+
118131
class ResponseAllRefArDO(BER_TLV_IE, tag=0xff40, nested=[RefArDO]):
119132
# SEID v1.1 Table 4-2
120133
pass
121134

135+
122136
class ResponseArDO(BER_TLV_IE, tag=0xff50, nested=[ArDO]):
123137
# SEID v1.1 Table 4-3
124138
pass
125139

140+
126141
class ResponseRefreshTagDO(BER_TLV_IE, tag=0xdf20):
127142
# SEID v1.1 Table 4-4
128143
_construct = Struct('refresh_tag'/HexAdapter(Bytes(8)))
129144

145+
130146
class DeviceInterfaceVersionDO(BER_TLV_IE, tag=0xe6):
131147
# SEID v1.1 Table 6-12
132148
_construct = Struct('major'/Int8ub, 'minor'/Int8ub, 'patch'/Int8ub)
133149

150+
134151
class DeviceConfigDO(BER_TLV_IE, tag=0xe4, nested=[DeviceInterfaceVersionDO]):
135152
# SEID v1.1 Table 6-10
136153
pass
137154

155+
138156
class ResponseDeviceConfigDO(BER_TLV_IE, tag=0xff7f, nested=[DeviceConfigDO]):
139157
# SEID v1.1 Table 5-14
140158
pass
141159

160+
142161
class AramConfigDO(BER_TLV_IE, tag=0xe5, nested=[DeviceInterfaceVersionDO]):
143162
# SEID v1.1 Table 6-11
144163
pass
145164

165+
146166
class ResponseAramConfigDO(BER_TLV_IE, tag=0xdf21, nested=[AramConfigDO]):
147167
# SEID v1.1 Table 4-5
148168
pass
149169

170+
150171
class CommandStoreRefArDO(BER_TLV_IE, tag=0xf0, nested=[RefArDO]):
151172
# SEID v1.1 Table 5-2
152173
pass
153174

175+
154176
class CommandDelete(BER_TLV_IE, tag=0xf1, nested=[AidRefDO, AidRefEmptyDO, RefDO, RefArDO]):
155177
# SEID v1.1 Table 5-4
156178
pass
157179

180+
158181
class CommandUpdateRefreshTagDO(BER_TLV_IE, tag=0xf2):
159182
# SEID V1.1 Table 5-6
160183
pass
161184

185+
162186
class CommandRegisterClientAidsDO(BER_TLV_IE, tag=0xf7, nested=[AidRefDO, AidRefEmptyDO]):
163187
# SEID v1.1 Table 5-7
164188
pass
165189

190+
166191
class CommandGet(BER_TLV_IE, tag=0xf3, nested=[AidRefDO, AidRefEmptyDO]):
167192
# SEID v1.1 Table 5-8
168193
pass
169194

195+
170196
class CommandGetAll(BER_TLV_IE, tag=0xf4):
171197
# SEID v1.1 Table 5-9
172198
pass
173199

200+
174201
class CommandGetClientAidsDO(BER_TLV_IE, tag=0xf6):
175202
# SEID v1.1 Table 5-10
176203
pass
177204

205+
178206
class CommandGetNext(BER_TLV_IE, tag=0xf5):
179207
# SEID v1.1 Table 5-11
180208
pass
181209

210+
182211
class CommandGetDeviceConfigDO(BER_TLV_IE, tag=0xf8):
183212
# SEID v1.1 Table 5-12
184213
pass
185214

215+
186216
class ResponseAracAidDO(BER_TLV_IE, tag=0xff70, nested=[AidRefDO, AidRefEmptyDO]):
187217
# SEID v1.1 Table 5-13
188218
pass
189219

220+
190221
class BlockDO(BER_TLV_IE, tag=0xe7):
191222
# SEID v1.1 Table 6-13
192223
_construct = Struct('offset'/Int16ub, 'length'/Int8ub)
@@ -197,11 +228,15 @@ class GetCommandDoCollection(TLV_IE_Collection, nested=[RefDO, DeviceConfigDO]):
197228
pass
198229

199230
# SEID v1.1 Table 4-2
231+
232+
200233
class GetResponseDoCollection(TLV_IE_Collection, nested=[ResponseAllRefArDO, ResponseArDO,
201234
ResponseRefreshTagDO, ResponseAramConfigDO]):
202235
pass
203236

204237
# SEID v1.1 Table 5-1
238+
239+
205240
class StoreCommandDoCollection(TLV_IE_Collection,
206241
nested=[BlockDO, CommandStoreRefArDO, CommandDelete,
207242
CommandUpdateRefreshTagDO, CommandRegisterClientAidsDO,
@@ -215,6 +250,7 @@ class StoreResponseDoCollection(TLV_IE_Collection,
215250
nested=[ResponseAllRefArDO, ResponseAracAidDO, ResponseDeviceConfigDO]):
216251
pass
217252

253+
218254
class ADF_ARAM(CardADF):
219255
def __init__(self, aid='a00000015141434c00', name='ADF.ARA-M', fid=None, sfid=None,
220256
desc='ARA-M Application'):
@@ -224,7 +260,7 @@ def __init__(self, aid='a00000015141434c00', name='ADF.ARA-M', fid=None, sfid=No
224260
self.add_files(files)
225261

226262
@staticmethod
227-
def xceive_apdu_tlv(tp, hdr:Hexstr, cmd_do, resp_cls, exp_sw='9000'):
263+
def xceive_apdu_tlv(tp, hdr: Hexstr, cmd_do, resp_cls, exp_sw='9000'):
228264
"""Transceive an APDU with the card, transparently encoding the command data from TLV
229265
and decoding the response data tlv."""
230266
if cmd_do:
@@ -259,7 +295,8 @@ def get_all(tp):
259295
@staticmethod
260296
def get_config(tp, v_major=0, v_minor=0, v_patch=1):
261297
cmd_do = DeviceConfigDO()
262-
cmd_do.from_dict([{'DeviceInterfaceVersionDO': {'major': v_major, 'minor': v_minor, 'patch': v_patch }}])
298+
cmd_do.from_dict([{'DeviceInterfaceVersionDO': {
299+
'major': v_major, 'minor': v_minor, 'patch': v_patch}}])
263300
return ADF_ARAM.xceive_apdu_tlv(tp, '80cadf21', cmd_do, ResponseAramConfigDO)
264301

265302
@with_default_category('Application-Specific Commands')
@@ -281,20 +318,30 @@ def do_aram_get_config(self, opts):
281318

282319
store_ref_ar_do_parse = argparse.ArgumentParser()
283320
# REF-DO
284-
store_ref_ar_do_parse.add_argument('--device-app-id', required=True, help='Identifies the specific device application that the rule appplies to. Hash of Certificate of Application Provider, or UUID. (20/32 hex bytes)')
321+
store_ref_ar_do_parse.add_argument(
322+
'--device-app-id', required=True, help='Identifies the specific device application that the rule appplies to. Hash of Certificate of Application Provider, or UUID. (20/32 hex bytes)')
285323
aid_grp = store_ref_ar_do_parse.add_mutually_exclusive_group()
286-
aid_grp.add_argument('--aid', help='Identifies the specific SE application for which rules are to be stored. Can be a partial AID, containing for example only the RID. (5-16 hex bytes)')
287-
aid_grp.add_argument('--aid-empty', action='store_true', help='No specific SE application, applies to all applications')
288-
store_ref_ar_do_parse.add_argument('--pkg-ref', help='Full Android Java package name (up to 127 chars ASCII)')
324+
aid_grp.add_argument(
325+
'--aid', help='Identifies the specific SE application for which rules are to be stored. Can be a partial AID, containing for example only the RID. (5-16 hex bytes)')
326+
aid_grp.add_argument('--aid-empty', action='store_true',
327+
help='No specific SE application, applies to all applications')
328+
store_ref_ar_do_parse.add_argument(
329+
'--pkg-ref', help='Full Android Java package name (up to 127 chars ASCII)')
289330
# AR-DO
290331
apdu_grp = store_ref_ar_do_parse.add_mutually_exclusive_group()
291-
apdu_grp.add_argument('--apdu-never', action='store_true', help='APDU access is not allowed')
292-
apdu_grp.add_argument('--apdu-always', action='store_true', help='APDU access is allowed')
293-
apdu_grp.add_argument('--apdu-filter', help='APDU filter: 4 byte CLA/INS/P1/P2 followed by 4 byte mask (8 hex bytes)')
332+
apdu_grp.add_argument(
333+
'--apdu-never', action='store_true', help='APDU access is not allowed')
334+
apdu_grp.add_argument(
335+
'--apdu-always', action='store_true', help='APDU access is allowed')
336+
apdu_grp.add_argument(
337+
'--apdu-filter', help='APDU filter: 4 byte CLA/INS/P1/P2 followed by 4 byte mask (8 hex bytes)')
294338
nfc_grp = store_ref_ar_do_parse.add_mutually_exclusive_group()
295-
nfc_grp.add_argument('--nfc-always', action='store_true', help='NFC event access is allowed')
296-
nfc_grp.add_argument('--nfc-never', action='store_true', help='NFC event access is not allowed')
297-
store_ref_ar_do_parse.add_argument('--android-permissions', help='Android UICC Carrier Privilege Permissions (8 hex bytes)')
339+
nfc_grp.add_argument('--nfc-always', action='store_true',
340+
help='NFC event access is allowed')
341+
nfc_grp.add_argument('--nfc-never', action='store_true',
342+
help='NFC event access is not allowed')
343+
store_ref_ar_do_parse.add_argument(
344+
'--android-permissions', help='Android UICC Carrier Privilege Permissions (8 hex bytes)')
298345

299346
@cmd2.with_argparser(store_ref_ar_do_parse)
300347
def do_aram_store_ref_ar_do(self, opts):
@@ -323,7 +370,7 @@ def do_aram_store_ref_ar_do(self, opts):
323370
ar_do_content += [{'NfcArDO': {'nfc_event_access_rule': 'never'}}]
324371
if opts.android_permissions:
325372
ar_do_content += [{'PermArDO': {'permissions': opts.android_permissions}}]
326-
d = [{'RefArDO': [{ 'RefDO': ref_do_content}, {'ArDO': ar_do_content }]}]
373+
d = [{'RefArDO': [{'RefDO': ref_do_content}, {'ArDO': ar_do_content}]}]
327374
csrado = CommandStoreRefArDO()
328375
csrado.from_dict(d)
329376
res_do = ADF_ARAM.store_data(self._cmd.card._scc._tp, csrado)
@@ -359,6 +406,7 @@ def do_aram_delete_all(self, opts):
359406
}
360407
}
361408

409+
362410
class CardApplicationARAM(CardApplication):
363411
def __init__(self):
364-
super().__init__('ARA-M', adf=ADF_ARAM(), sw=sw_aram)
412+
super().__init__('ARA-M', adf=ADF_ARAM(), sw=sw_aram)

0 commit comments

Comments
 (0)