From 5998a3a8b3339076269692ad09761c2ffb7c43e6 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 16 Nov 2021 15:16:39 +0100 Subject: [PATCH] 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 --- pySim/profile.py | 3 ++- pySim/sysmocom_sja2.py | 2 +- pySim/ts_102_221.py | 44 +++++++++++++++++++----------------------- pySim/ts_31_102.py | 2 +- pySim/ts_31_103.py | 2 +- pySim/ts_51_011.py | 3 ++- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/pySim/profile.py b/pySim/profile.py index f068d7cd..768064f2 100644 --- a/pySim/profile.py +++ b/pySim/profile.py @@ -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 diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py index 263999d0..6d49572a 100644 --- a/pySim/sysmocom_sja2.py +++ b/pySim/sysmocom_sja2.py @@ -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'): diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py index 53cd1180..1d109883 100644 --- a/pySim/ts_102_221.py +++ b/pySim/ts_102_221.py @@ -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: diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py index 14d7ec1e..647a4d7f 100644 --- a/pySim/ts_31_102.py +++ b/pySim/ts_31_102.py @@ -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): diff --git a/pySim/ts_31_103.py b/pySim/ts_31_103.py index 63ef99ea..9c7843fb 100644 --- a/pySim/ts_31_103.py +++ b/pySim/ts_31_103.py @@ -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 = { diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py index 2d3ad0c2..f330460b 100644 --- a/pySim/ts_51_011.py +++ b/pySim/ts_51_011.py @@ -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',