profile: decode_select_response can be a static method

The method decode_select_response does not access any property of the
object. This means the method can be static.

Change-Id: Idd7aaebcf1ab0099cd40a88b8938604e84d8a88b
This commit is contained in:
Philipp Maier 2021-11-16 15:16:39 +01:00
parent 825b564115
commit 5998a3a8b3
6 changed files with 27 additions and 29 deletions

View File

@ -106,7 +106,8 @@ class CardProfile(object):
"""
return interpret_sw(self.sw, sw)
def decode_select_response(self, data_hex:str) -> Any:
@staticmethod
def decode_select_response(data_hex:str) -> Any:
"""Decode the response to a SELECT command.
This is the fall-back method which doesn't perform any decoding. It mostly

View File

@ -154,7 +154,7 @@ class DF_SYSTEM(CardDF):
self.add_files(files)
def decode_select_response(self, resp_hex):
return pySim.ts_102_221.decode_select_response(resp_hex)
return pySim.ts_102_221.CardProfileUICC.decode_select_response(resp_hex)
class EF_USIM_SQN(TransparentEF):
def __init__(self, fid='af30', name='EF.USIM_SQN'):

View File

@ -473,28 +473,6 @@ Never_DO = TL0_DataObject('never', 'Never', 0x97)
SC_DO = DataObjectChoice('security_condition', 'Security Condition',
members=[Always_DO, Never_DO, SecCondByte_DO(), SecCondByte_DO(0x9e), CRT_DO()])
# ETSI TS 102 221 Section 11.1.1.3
def decode_select_response(resp_hex):
fixup_fcp_proprietary_tlv_map(FCP_Proprietary_TLV_MAP)
resp_hex = resp_hex.upper()
# outer layer
fcp_base_tlv = TLV(['62'])
fcp_base = fcp_base_tlv.parse(resp_hex)
# actual FCP
fcp_tlv = TLV(FCP_TLV_MAP)
fcp = fcp_tlv.parse(fcp_base['62'])
# further decode the proprietary information
if fcp['A5']:
prop_tlv = TLV(FCP_Proprietary_TLV_MAP)
prop = prop_tlv.parse(fcp['A5'])
fcp['A5'] = tlv_val_interpret(FCP_prorietary_interpreter_map, prop)
fcp['A5'] = tlv_key_replace(FCP_Proprietary_TLV_MAP, fcp['A5'])
# finally make sure we get human-readable keys in the output dict
r = tlv_val_interpret(FCP_interpreter_map, fcp)
return tlv_key_replace(FCP_TLV_MAP, r)
# TS 102 221 Section 13.1
class EF_DIR(LinFixedEF):
def __init__(self, fid='2f00', sfid=0x1e, name='EF.DIR', desc='Application Directory'):
@ -694,8 +672,26 @@ class CardProfileUICC(CardProfile):
super().__init__(name, desc='ETSI TS 102 221', cla="00", sel_ctrl="0004", files_in_mf=files, sw=sw)
def decode_select_response(self, data_hex:str) -> Any:
return decode_select_response(data_hex)
@staticmethod
def decode_select_response(resp_hex:str) -> Any:
"""ETSI TS 102 221 Section 11.1.1.3"""
fixup_fcp_proprietary_tlv_map(FCP_Proprietary_TLV_MAP)
resp_hex = resp_hex.upper()
# outer layer
fcp_base_tlv = TLV(['62'])
fcp_base = fcp_base_tlv.parse(resp_hex)
# actual FCP
fcp_tlv = TLV(FCP_TLV_MAP)
fcp = fcp_tlv.parse(fcp_base['62'])
# further decode the proprietary information
if fcp['A5']:
prop_tlv = TLV(FCP_Proprietary_TLV_MAP)
prop = prop_tlv.parse(fcp['A5'])
fcp['A5'] = tlv_val_interpret(FCP_prorietary_interpreter_map, prop)
fcp['A5'] = tlv_key_replace(FCP_Proprietary_TLV_MAP, fcp['A5'])
# finally make sure we get human-readable keys in the output dict
r = tlv_val_interpret(FCP_interpreter_map, fcp)
return tlv_key_replace(FCP_TLV_MAP, r)
@staticmethod
def match_with_card(scc:SimCardCommands) -> bool:

View File

@ -1067,7 +1067,7 @@ class ADF_USIM(CardADF):
self.add_files(files)
def decode_select_response(self, data_hex):
return pySim.ts_102_221.decode_select_response(data_hex)
return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
@with_default_category('Application-Specific Commands')
class AddlShellCommands(CommandSet):

View File

@ -213,7 +213,7 @@ class ADF_ISIM(CardADF):
self.shell_commands += [ADF_USIM.AddlShellCommands()]
def decode_select_response(self, data_hex):
return pySim.ts_102_221.decode_select_response(data_hex)
return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
# TS 31.103 Section 7.1
sw_isim = {

View File

@ -978,7 +978,8 @@ class CardProfileSIM(CardProfile):
super().__init__('SIM', desc='GSM SIM Card', cla="a0", sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw)
def decode_select_response(self, resp_hex:str) -> Any:
@staticmethod
def decode_select_response(resp_hex:str) -> Any:
resp_bin = h2b(resp_hex)
struct_of_file_map = {
0: 'transparent',