lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

February 2024

  • 1 participants
  • 1748 discussions
[S] Change in pysim[master]: pylint: esim/saip/templates.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35835?usp=email ) Change subject: pylint: esim/saip/templates.py ...................................................................... pylint: esim/saip/templates.py pySim/esim/saip/templates.py:106:0: R1707: Disallow trailing comma tuple (trailing-comma-tuple) pySim/esim/saip/templates.py:56:37: C0121: Comparison 'self.fid != None' should be 'self.fid is not None' (singleton-comparison) pySim/esim/saip/templates.py:57:28: C0121: Comparison 'self.arr != None' should be 'self.arr is not None' (singleton-comparison) pySim/esim/saip/templates.py:58:37: C0121: Comparison 'self.sfi != None' should be 'self.sfi is not None' (singleton-comparison) pySim/esim/saip/templates.py:96:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) pySim/esim/saip/templates.py:591:0: W1404: Implicit string concatenation found in list (implicit-str-concat) Change-Id: I181578ba630c8bdb558297e990411b59593652a0 --- M pySim/esim/saip/templates.py 1 file changed, 22 insertions(+), 6 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim/esim/saip/templates.py b/pySim/esim/saip/templates.py index 44c2ac5..cd76247 100644 --- a/pySim/esim/saip/templates.py +++ b/pySim/esim/saip/templates.py @@ -53,9 +53,9 @@ return "FileTemplate(%s)" % (self.name) def __repr__(self) -> str: - s_fid = "%04x" % self.fid if self.fid != None else 'None' - s_arr = self.arr if self.arr != None else 'None' - s_sfi = "%02x" % self.sfi if self.sfi != None else 'None' + s_fid = "%04x" % self.fid if self.fid is not None else 'None' + s_arr = self.arr if self.arr is not None else 'None' + s_sfi = "%02x" % self.sfi if self.sfi is not None else 'None' return "FileTemplate(%s/%s, %s, %s, arr=%s, sfi=%s)" % (self.name, self.pe_name, s_fid, self.file_type, s_arr, s_sfi) @@ -93,7 +93,7 @@ def get_by_oid(cls, oid: Union[List[int], str]) -> Optional[ProfileTemplate]: """Look-up the ProfileTemplate based on its OID. The OID can be given either in dotted-string format, or as a list of integers.""" - if type(oid) is not str: + if not isinstance(oid, str): oid = OID.OID.str_from_intlist(oid) return cls.by_oid.get(oid, None) @@ -103,7 +103,7 @@ # Section 9.2 class FilesAtMF(ProfileTemplate): created_by_default = True - oid = OID.MF, + oid = OID.MF files = [ FileTemplate(0x3f00, 'MF', 'MF', None, None, 14, None, None, None, params=['pinStatusTemplateDO']), FileTemplate(0x2f05, 'EF.PL', 'TR', None, 2, 1, 0x05, 'FF...FF', None), @@ -588,7 +588,7 @@ created_by_default = True oid = OID.ADF_ISIM_by_default files = [ - FileTemplate( None, 'ADF.ISIM', 'ADF', None, None, 14, None, None, False, ['aid','temporary_fid''pinStatusTemplateDO']), + FileTemplate( None, 'ADF.ISIM', 'ADF', None, None, 14, None, None, False, ['aid','temporary_fid','pinStatusTemplateDO']), FileTemplate(0x6f02, 'EF.IMPI', 'TR', None, None, 2, 0x02, None, True, ['size']), FileTemplate(0x6f04, 'EF.IMPU', 'LF', 1, None, 2, 0x04, None, True, ['size']), FileTemplate(0x6f03, 'EF.Domain', 'TR', None, None, 2, 0x05, None, True, ['size']), -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35835?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I181578ba630c8bdb558297e990411b59593652a0 Gerrit-Change-Number: 35835 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: esim/saip/oid.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35836?usp=email ) Change subject: pylint: esim/saip/oid.py ...................................................................... pylint: esim/saip/oid.py pySim/esim/saip/oid.py:30:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) pySim/esim/saip/oid.py:46:11: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) Change-Id: I65c9cd1bb2b6a1747a7fbb25052adc75605bc870 --- M pySim/esim/saip/oid.py 1 file changed, 14 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/esim/saip/oid.py b/pySim/esim/saip/oid.py index e1892be..238e49f 100644 --- a/pySim/esim/saip/oid.py +++ b/pySim/esim/saip/oid.py @@ -27,7 +27,7 @@ return '.'.join([str(x) for x in intlist]) def __init__(self, initializer: Union[List[int], str]): - if type(initializer) == str: + if isinstance(initializer, str): self.intlist = self.intlist_from_str(initializer) else: self.intlist = initializer @@ -43,7 +43,7 @@ """OID helper for TCA eUICC prefix""" __prefix = [2,23,143,1] def __init__(self, initializer): - if type(initializer) == str: + if isinstance(initializer, str): initializer = self.intlist_from_str(initializer) super().__init__(self.__prefix + initializer) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35836?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I65c9cd1bb2b6a1747a7fbb25052adc75605bc870 Gerrit-Change-Number: 35836 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: cdma_ruim.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35838?usp=email ) Change subject: pylint: cdma_ruim.py ...................................................................... pylint: cdma_ruim.py pySim/cdma_ruim.py:30:0: W0401: Wildcard import construct (wildcard-import) pySim/cdma_ruim.py:188:4: W0237: Parameter 'data_hex' has been renamed to 'resp_hex' in overriding 'CardProfileRUIM.decode_select_response' method (arguments-renamed) pySim/cdma_ruim.py:30:0: C0411: third party import "from construct import *" should be placed before "from pySim.utils import *" (wrong-import-order) Change-Id: I4c384f37a6a317c6eddef8742572fcfa76a5fc20 --- M pySim/cdma_ruim.py 1 file changed, 17 insertions(+), 3 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim/cdma_ruim.py b/pySim/cdma_ruim.py index ad50e60..d16aefc 100644 --- a/pySim/cdma_ruim.py +++ b/pySim/cdma_ruim.py @@ -19,6 +19,8 @@ import enum +from construct import Bytewise, BitStruct, BitsInteger, Struct, FlagsEnum + from pySim.utils import * from pySim.filesystem import * from pySim.profile import match_ruim @@ -27,7 +29,6 @@ from pySim.ts_51_011 import DF_TELECOM, DF_GSM from pySim.ts_51_011 import EF_ServiceTable from pySim.construct import * -from construct import * # Mapping between CDMA Service Number and its description @@ -185,9 +186,9 @@ sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM(), DF_CDMA()]) @staticmethod - def decode_select_response(resp_hex: str) -> object: + def decode_select_response(data_hex: str) -> object: # TODO: Response parameters/data in case of DF_CDMA (section 2.6) - return CardProfileSIM.decode_select_response(resp_hex) + return CardProfileSIM.decode_select_response(data_hex) @staticmethod def match_with_card(scc: SimCardCommands) -> bool: -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35838?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I4c384f37a6a317c6eddef8742572fcfa76a5fc20 Gerrit-Change-Number: 35838 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pylint: global_platform/scp.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35837?usp=email ) Change subject: pylint: global_platform/scp.py ...................................................................... pylint: global_platform/scp.py pySim/global_platform/scp.py:27:0: W0404: Reimport 'Optional' (imported line 20) (reimported) pySim/global_platform/scp.py:157:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/global_platform/scp.py:165:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/global_platform/scp.py:182:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/global_platform/scp.py:189:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/global_platform/scp.py:266:4: W0221: Variadics removed in overriding 'SCP02._wrap_cmd_apdu' method (arguments-differ) pySim/global_platform/scp.py:298:4: W0237: Parameter 'rsp_apdu' has been renamed to 'apdu' in overriding 'SCP02.unwrap_rsp_apdu' method (arguments-renamed) pySim/global_platform/scp.py:314:7: C0121: Comparison 'l == None' should be 'l is None' (singleton-comparison) pySim/global_platform/scp.py:436:11: C0121: Comparison 'host_challenge == None' should be 'host_challenge is None' (singleton-comparison) pySim/global_platform/scp.py:506:4: W0237: Parameter 'rsp_apdu' has been renamed to 'apdu' in overriding 'SCP03.unwrap_rsp_apdu' method (arguments-renamed) pySim/global_platform/scp.py:27:0: C0411: standard import "from typing import Optional" should be placed before "from Cryptodome.Cipher import DES3, DES" (wrong-import-order) Change-Id: Idd2b779a6628c88d9a48c94b8581525209824426 --- M pySim/global_platform/scp.py 1 file changed, 36 insertions(+), 18 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim/global_platform/scp.py b/pySim/global_platform/scp.py index 4e64e41..0804492 100644 --- a/pySim/global_platform/scp.py +++ b/pySim/global_platform/scp.py @@ -24,15 +24,14 @@ from construct import Optional as COptional from pySim.utils import b2h, bertlv_parse_len, bertlv_encode_len from pySim.secure_channel import SecureChannel -from typing import Optional logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) def scp02_key_derivation(constant: bytes, counter: int, base_key: bytes) -> bytes: - assert(len(constant) == 2) + assert len(constant) == 2 assert(counter >= 0 and counter <= 65535) - assert(len(base_key) == 16) + assert len(base_key) == 16 derivation_data = constant + counter.to_bytes(2, 'big') + b'\x00' * 12 cipher = DES3.new(base_key, DES.MODE_CBC, b'\x00' * 8) @@ -156,8 +155,7 @@ # only protect those APDUs that actually are global platform commands if apdu[0] & 0x80: return self._wrap_cmd_apdu(apdu, *args, **kwargs) - else: - return apdu + return apdu @abc.abstractmethod def _wrap_cmd_apdu(self, apdu: bytes, *args, **kwargs) -> bytes: @@ -181,8 +179,7 @@ num_pad = len(key) % self.sk.blocksize if num_pad: return bertlv_encode_len(len(key)) + self.dek_encrypt(key + b'\x00'*num_pad) - else: - return self.dek_encrypt(key) + return self.dek_encrypt(key) def decrypt_key(self, encrypted_key:bytes) -> bytes: """Decrypt a key with the DEK.""" @@ -263,7 +260,7 @@ mac = self.sk.calc_mac_1des(header + self.host_cryptogram, True) return bytes([self._cla(True), INS_EXT_AUTH, self.security_level, 0, 16]) + self.host_cryptogram + mac - def _wrap_cmd_apdu(self, apdu: bytes) -> bytes: + def _wrap_cmd_apdu(self, apdu: bytes, *args, **kwargs) -> bytes: """Wrap Command APDU for SCP02: calculate MAC and encrypt.""" lc = len(apdu) - 5 assert len(apdu) >= 5, "Wrong APDU length: %d" % len(apdu) @@ -295,9 +292,9 @@ apdu = bytes([self._cla(True, b8)]) + apdu[1:4] + bytes([lc]) + data + mac return apdu - def unwrap_rsp_apdu(self, sw: bytes, apdu: bytes) -> bytes: + def unwrap_rsp_apdu(self, sw: bytes, rsp_apdu: bytes) -> bytes: # TODO: Implement R-MAC / R-ENC - return apdu + return rsp_apdu @@ -311,7 +308,7 @@ def prf(key: bytes, data:bytes): return CMAC.new(key, data, AES).digest() - if l == None: + if l is None: l = len(base_key) * 8 logger.debug("scp03_kdf(constant=%s, context=%s, base_key=%s, l=%u)", b2h(constant), b2h(context), b2h(base_key), l) @@ -433,7 +430,7 @@ def gen_init_update_apdu(self, host_challenge: Optional[bytes] = None) -> bytes: """Generate INITIALIZE UPDATE APDU.""" - if host_challenge == None: + if host_challenge is None: host_challenge = b'\x00' * self.s_mode if len(host_challenge) != self.s_mode: raise ValueError('Host Challenge must be %u bytes long' % self.s_mode) @@ -503,20 +500,20 @@ return mapdu - def unwrap_rsp_apdu(self, sw: bytes, apdu: bytes) -> bytes: + def unwrap_rsp_apdu(self, sw: bytes, rsp_apdu: bytes) -> bytes: # No R-MAC shall be generated and no protection shall be applied to a response that includes an error # status word: in this case only the status word shall be returned in the response. All status words # except '9000' and warning status words (i.e. '62xx' and '63xx') shall be interpreted as error status # words. - logger.debug("unwrap_rsp_apdu(sw=%s, apdu=%s)", sw, apdu) + logger.debug("unwrap_rsp_apdu(sw=%s, rsp_apdu=%s)", sw, rsp_apdu) if not self.do_rmac: assert not self.do_renc - return apdu + return rsp_apdu if sw != b'\x90\x00' and sw[0] not in [0x62, 0x63]: - return apdu - response_data = apdu[:-self.s_mode] - rmac = apdu[-self.s_mode:] + return rsp_apdu + response_data = rsp_apdu[:-self.s_mode] + rmac = rsp_apdu[-self.s_mode:] rmac_exp = self.sk.calc_rmac(response_data + sw)[:self.s_mode] if rmac != rmac_exp: raise ValueError("R-MAC value not matching: received: %s, computed: %s" % (rmac, rmac_exp)) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35837?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Idd2b779a6628c88d9a48c94b8581525209824426 Gerrit-Change-Number: 35837 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: sysmocom_sja2.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35839?usp=email ) Change subject: pylint: sysmocom_sja2.py ...................................................................... pylint: sysmocom_sja2.py pySim/sysmocom_sja2.py:20:0: W0401: Wildcard import pytlv.TLV (wildcard-import) pySim/sysmocom_sja2.py:27:0: W0401: Wildcard import construct (wildcard-import) pySim/sysmocom_sja2.py:21:0: C0411: standard import "from struct import pack, unpack" should be placed before "from pytlv.TLV import *" (wrong-import-order) pySim/sysmocom_sja2.py:27:0: C0411: third party import "from construct import *" should be placed before "from pySim.utils import *" (wrong-import-order) pySim/sysmocom_sja2.py:21:0: W0611: Unused pack imported from struct (unused-import) pySim/sysmocom_sja2.py:25:0: W0611: Unused CardProfileUICC imported from pySim.ts_102_221 (unused-import) Change-Id: I0e5b5c6f3179f9710464af4cba91d682412b8a09 --- M pySim/sysmocom_sja2.py 1 file changed, 22 insertions(+), 5 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py index 5bec446..eb53520 100644 --- a/pySim/sysmocom_sja2.py +++ b/pySim/sysmocom_sja2.py @@ -17,14 +17,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ -from pytlv.TLV import * -from struct import pack, unpack +from struct import unpack +from construct import FlagsEnum, Byte, Struct, Int8ub, Bytes, Mapping, Enum, Padding, BitsInteger +from construct import Bit, this, Int32ub, Int16ub, Nibble, BytesInteger, GreedyRange +from construct import Optional as COptional + from pySim.utils import * from pySim.filesystem import * from pySim.runtime import RuntimeState -from pySim.ts_102_221 import CardProfileUICC from pySim.construct import * -from construct import * import pySim key_type2str = { @@ -70,7 +71,7 @@ 'attempts_remaining'/Int8ub, 'maximum_attempts'/Int8ub, 'pin'/HexAdapter(Rpad(Bytes(8))), - 'puk'/Optional(PukStruct)) + 'puk'/COptional(PukStruct)) class EF_MILENAGE_CFG(TransparentEF): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35839?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I0e5b5c6f3179f9710464af4cba91d682412b8a09 Gerrit-Change-Number: 35839 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pylint: ts_31_102.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35840?usp=email ) Change subject: pylint: ts_31_102.py ...................................................................... pylint: ts_31_102.py Change-Id: I5b72ad476d338aa4048bb15a74796ef69191f028 --- M pySim/ts_31_102.py 1 file changed, 26 insertions(+), 27 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py index 0614a0c..0ddf218 100644 --- a/pySim/ts_31_102.py +++ b/pySim/ts_31_102.py @@ -26,7 +26,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -# Mapping between USIM Service Number and its description +import enum + +from construct import Optional as COptional +from construct import Int32ub, Nibble, GreedyRange, Struct, FlagsEnum, Switch, this, Int16ub, Padding +from construct import Bytewise, Int24ub, PaddedString + import pySim.ts_102_221 from pySim.ts_51_011 import EF_ACMmax, EF_AAeM, EF_eMLPP, EF_CMI, EF_PNN from pySim.ts_51_011 import EF_MMSN, EF_MMSICP, EF_MMSUP, EF_MMSUCP, EF_VGCS, EF_VGCSS, EF_NIA @@ -41,11 +46,8 @@ from pySim.construct import * from pySim.utils import is_hexstr from pySim.cat import SMS_TPDU, DeviceIdentities, SMSPPDownload -from construct import Optional as COptional -from construct import * -from typing import Tuple -from struct import unpack, pack -import enum + +# Mapping between USIM Service Number and its description EF_UST_map = { 1: 'Local Phone Book', 2: 'Fixed Dialling Numbers (FDN)', @@ -400,15 +402,15 @@ desc='Language Indication'): super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) - def _decode_record_bin(self, in_bin, **kwargs): + def _decode_record_bin(self, in_bin, **_kwargs): if in_bin == b'\xff\xff': return None else: # officially this is 7-bit GSM alphabet with one padding bit in each byte return in_bin.decode('ascii') - def _encode_record_bin(self, in_json, **kwargs): - if in_json == None: + def _encode_record_bin(self, in_json, **_kwargs): + if in_json is None: return b'\xff\xff' else: # officially this is 7-bit GSM alphabet with one padding bit in each byte @@ -438,9 +440,6 @@ @with_default_category('File-Specific Commands') class AddlShellCommands(CommandSet): - def __init__(self): - super().__init__() - def do_ust_service_activate(self, arg): """Activate a service within EF.UST""" selected_file = self._cmd.lchan.selected_file @@ -451,7 +450,7 @@ selected_file = self._cmd.lchan.selected_file selected_file.ust_update(self._cmd, [], [int(arg)]) - def do_ust_service_check(self, arg): + def do_ust_service_check(self, _arg): """Check consistency between services of this file and files present/activated. Many services determine if one or multiple files shall be present/activated or if they shall be @@ -503,7 +502,7 @@ desc='Emergency Call Codes'): super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(4, 20)) - def _decode_record_bin(self, in_bin, **kwargs): + def _decode_record_bin(self, in_bin, **_kwargs): # mandatory parts code = in_bin[:3] if code == b'\xff\xff\xff': @@ -517,7 +516,7 @@ ret['alpha_id'] = parse_construct(EF_ECC.alpha_construct, alpha_id) return ret - def _encode_record_bin(self, in_json, **kwargs): + def _encode_record_bin(self, in_json, **_kwargs): if in_json is None: return b'\xff\xff\xff\xff' code = EF_ECC.cc_construct.build(in_json['call_code']) @@ -638,9 +637,6 @@ @with_default_category('File-Specific Commands') class AddlShellCommands(CommandSet): - def __init__(self): - super().__init__() - def do_est_service_enable(self, arg): """Enable a service within EF.EST""" selected_file = self._cmd.lchan.selected_file @@ -683,7 +679,7 @@ def __init__(self, fid='6f65', sfid=None, name='EF.RPLMNAcTD', size=(2, 4), rec_len=2, desc='RPLMN Last used Access Technology', **kwargs): super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) - def _decode_record_hex(self, in_hex, **kwargs): + def _decode_record_hex(self, in_hex, **_kwargs): return dec_act(in_hex) # TODO: Encode @@ -1139,9 +1135,6 @@ @with_default_category('File-Specific Commands') class AddlShellCommands(CommandSet): - def __init__(self): - super().__init__() - def do_prose_service_activate(self, arg): """Activate a service within EF.5G_PROSE_ST""" selected_file = self._cmd.lchan.selected_file @@ -1585,9 +1578,6 @@ @with_default_category('Application-Specific Commands') class AddlShellCommands(CommandSet): - def __init__(self): - super().__init__() - authenticate_parser = argparse.ArgumentParser() authenticate_parser.add_argument('rand', type=is_hexstr, help='Random challenge') authenticate_parser.add_argument('autn', type=is_hexstr, help='Authentication Nonce') @@ -1596,7 +1586,7 @@ @cmd2.with_argparser(authenticate_parser) def do_authenticate(self, opts): """Perform Authentication and Key Agreement (AKA).""" - (data, sw) = self._cmd.lchan.scc.authenticate(opts.rand, opts.autn) + (data, _sw) = self._cmd.lchan.scc.authenticate(opts.rand, opts.autn) self._cmd.poutput_json(data) term_prof_parser = argparse.ArgumentParser() @@ -1654,7 +1644,7 @@ context = 0x01 # SUCI if opts.nswo_context: context = 0x02 # SUCI 5G NSWO - (data, sw) = self._cmd.lchan.scc.get_identity(context) + (data, _sw) = self._cmd.lchan.scc.get_identity(context) do = SUCI_TlvDataObject() do.from_tlv(h2b(data)) do_d = do.to_dict() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35840?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I5b72ad476d338aa4048bb15a74796ef69191f028 Gerrit-Change-Number: 35840 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: transport/serial.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35823?usp=email ) Change subject: pylint: transport/serial.py ...................................................................... pylint: transport/serial.py pySim/transport/serial.py:54:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) pySim/transport/serial.py:89:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) pySim/transport/serial.py:225:0: C0325: Unnecessary parens after 'while' keyword (superfluous-parens) pySim/transport/serial.py:63:12: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/transport/serial.py:106:8: R1720: Unnecessary "elif" after "raise", remove the leading "el" from "elif" (no-else-raise) pySim/transport/serial.py:124:12: W0707: Consider explicitly re-raising using 'except Exception as exc' and 'raise ValueError('Invalid reset pin %s' % self._rst_pin) from exc' (raise-missing-from) pySim/transport/serial.py:204:12: R1723: Unnecessary "elif" after "break", remove the leading "el" from "elif" (no-else-break) pySim/transport/serial.py:20:0: C0411: standard import "import time" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:21:0: C0411: standard import "import os" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:22:0: C0411: standard import "import argparse" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:23:0: C0411: standard import "from typing import Optional" should be placed before "import serial" (wrong-import-order) Change-Id: I82ef12492615a18a13cbdecf0371b3a5d02bbd5c --- M pySim/transport/serial.py 1 file changed, 30 insertions(+), 10 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index 06a082a..b4eddcd 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -16,11 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import serial import time import os import argparse from typing import Optional +import serial from pySim.exceptions import NoCardError, ProtocolError from pySim.transport import LinkBase @@ -51,7 +51,7 @@ self._atr = None def __del__(self): - if (hasattr(self, "_sl")): + if hasattr(self, "_sl"): self._sl.close() def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False): @@ -62,8 +62,7 @@ self.reset_card() if not newcardonly: return - else: - existing = True + existing = True except NoCardError: pass @@ -86,7 +85,7 @@ # Tolerate a couple of protocol error ... can happen if # we try when the card is 'half' inserted pe += 1 - if (pe > 2): + if pe > 2: raise # Timed out ... @@ -105,7 +104,7 @@ rv = self._reset_card() if rv == 0: raise NoCardError() - elif rv < 0: + if rv < 0: raise ProtocolError() return rv @@ -120,8 +119,8 @@ try: rst_meth = rst_meth_map[self._rst_pin[1:]] rst_val = rst_val_map[self._rst_pin[0]] - except: - raise ValueError('Invalid reset pin %s' % self._rst_pin) + except Exception as exc: + raise ValueError('Invalid reset pin %s' % self._rst_pin) from exc rst_meth(rst_val) time.sleep(0.1) # 100 ms @@ -203,7 +202,7 @@ b = self._rx_byte() if ord(b) == pdu[1]: break - elif b != '\x60': + if b != '\x60': # Ok, it 'could' be SW1 sw1 = b sw2 = self._rx_byte() @@ -222,7 +221,7 @@ to_recv = data_len - len(pdu) + 5 + 2 data = bytes(0) - while (len(data) < to_recv): + while len(data) < to_recv: b = self._rx_byte() if (to_recv == 2) and (b == '\x60'): # Ignore NIL if we have no RX data (hack ?) continue -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35823?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I82ef12492615a18a13cbdecf0371b3a5d02bbd5c Gerrit-Change-Number: 35823 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: pylint: transport/modem_atcmd.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35821?usp=email ) Change subject: pylint: transport/modem_atcmd.py ...................................................................... pylint: transport/modem_atcmd.py pySim/transport/modem_atcmd.py:70:0: C0325: Unnecessary parens after 'assert' keyword (superfluous-parens) pySim/transport/modem_atcmd.py:28:0: W0401: Wildcard import pySim.exceptions (wildcard-import) pySim/transport/modem_atcmd.py:60:22: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) pySim/transport/modem_atcmd.py:72:12: W0707: Consider explicitly re-raising using 'except Exception as exc' and 'raise ReaderError('Failed to send AT command: %s' % cmd) from exc' (raise-missing-from) pySim/transport/modem_atcmd.py:120:12: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return) pySim/transport/modem_atcmd.py:138:8: W1201: Use lazy % formatting in logging functions (logging-not-lazy) pySim/transport/modem_atcmd.py:170:12: W0707: Consider explicitly re-raising using 'except Exception as exc' and 'raise ReaderError('Failed to parse response from modem: %s' % rsp) from exc' (raise-missing-from) pySim/transport/modem_atcmd.py:168:13: W0612: Unused variable 'rsp_pdu_len' (unused-variable) pySim/transport/modem_atcmd.py:21:0: C0411: standard import "import time" should be placed before "import serial" (wrong-import-order) pySim/transport/modem_atcmd.py:22:0: C0411: standard import "import re" should be placed before "import serial" (wrong-import-order) pySim/transport/modem_atcmd.py:23:0: C0411: standard import "import argparse" should be placed before "import serial" (wrong-import-order) pySim/transport/modem_atcmd.py:24:0: C0411: standard import "from typing import Optional" should be placed before "import serial" (wrong-import-order) pySim/transport/modem_atcmd.py:28:0: W0614: Unused import(s) NoCardError and SwMatchError from wildcard import of pySim.exceptions (unused-wildcard-import) Change-Id: I2c8994eabd973b65132af1030429b1021d0c20df --- M pySim/transport/modem_atcmd.py 1 file changed, 36 insertions(+), 15 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index a05d6c4..5943e3a 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -17,15 +17,15 @@ # import logging as log -import serial import time import re import argparse from typing import Optional +import serial from pySim.utils import Hexstr, ResTuple from pySim.transport import LinkBase -from pySim.exceptions import * +from pySim.exceptions import ReaderError, ProtocolError # HACK: if somebody needs to debug this thing # log.root.setLevel(log.DEBUG) @@ -57,7 +57,7 @@ def send_at_cmd(self, cmd, timeout=0.2, patience=0.002): # Convert from string to bytes, if needed - bcmd = cmd if type(cmd) is bytes else cmd.encode() + bcmd = cmd if isinstance(cmd, bytes) else cmd.encode() bcmd += b'\r' # Clean input buffer from previous/unexpected data @@ -67,9 +67,9 @@ log.debug('Sending AT command: %s', cmd) try: wlen = self._sl.write(bcmd) - assert(wlen == len(bcmd)) - except: - raise ReaderError('Failed to send AT command: %s' % cmd) + assert wlen == len(bcmd) + except Exception as exc: + raise ReaderError('Failed to send AT command: %s' % cmd) from exc rsp = b'' its = 1 @@ -91,8 +91,7 @@ break time.sleep(patience) its += 1 - log.debug('Command took %0.6fs (%d cycles a %fs)', - time.time() - t_start, its, patience) + log.debug('Command took %0.6fs (%d cycles a %fs)', time.time() - t_start, its, patience) if self._echo: # Skip echo chars @@ -120,11 +119,10 @@ if result[-1] == b'OK': self._echo = False return - elif result[-1] == b'AT\r\r\nOK': + if result[-1] == b'AT\r\r\nOK': self._echo = True return - raise ReaderError( - 'Interface \'%s\' does not respond to \'AT\' command' % self._device) + raise ReaderError('Interface \'%s\' does not respond to \'AT\' command' % self._device) def reset_card(self): # Reset the modem, just to be sure @@ -135,7 +133,7 @@ if self.send_at_cmd('AT+CSIM=?') != [b'OK']: raise ReaderError('The modem does not seem to support SIM access') - log.info('Modem at \'%s\' is ready!' % self._device) + log.info('Modem at \'%s\' is ready!', self._device) def connect(self): pass # Nothing to do really ... @@ -165,9 +163,9 @@ # Make sure that the response has format: b'+CSIM: %d,\"%s\"' try: result = re.match(b'\+CSIM: (\d+),\"([0-9A-F]+)\"', rsp) - (rsp_pdu_len, rsp_pdu) = result.groups() - except: - raise ReaderError('Failed to parse response from modem: %s' % rsp) + (_rsp_pdu_len, rsp_pdu) = result.groups() + except Exception as exc: + raise ReaderError('Failed to parse response from modem: %s' % rsp) from exc # TODO: make sure we have at least SW data = rsp_pdu[:-4].decode().lower() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35821?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I2c8994eabd973b65132af1030429b1021d0c20df Gerrit-Change-Number: 35821 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: apdu_source/__init__.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35825?usp=email ) Change subject: pylint: apdu_source/__init__.py ...................................................................... pylint: apdu_source/__init__.py pySim/apdu_source/__init__.py:1:0: C0114: Missing module docstring (missing-module-docstring) pySim/apdu_source/__init__.py:17:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/apdu_source/__init__.py:34:16: W0133: Exception statement has no effect (pointless-exception-statement) Change-Id: Iec552afd6004b849132132642910a4c7f91e3473 --- M pySim/apdu_source/__init__.py 1 file changed, 14 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/apdu_source/__init__.py b/pySim/apdu_source/__init__.py index 098d3ca..99df865 100644 --- a/pySim/apdu_source/__init__.py +++ b/pySim/apdu_source/__init__.py @@ -14,7 +14,6 @@ @abc.abstractmethod def read_packet(self) -> PacketType: """Read one packet from the source.""" - pass def read(self) -> Union[Apdu, CardReset]: """Main function to call by the user: Blocking read, returns Apdu or CardReset.""" @@ -31,5 +30,5 @@ elif isinstance(r, CardReset): apdu = r else: - ValueError('Unknown read_packet() return %s' % r) + raise ValueError('Unknown read_packet() return %s' % r) return apdu -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35825?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Iec552afd6004b849132132642910a4c7f91e3473 Gerrit-Change-Number: 35825 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: pylint: transport/pcsc.py
by laforge 05 Feb '24

05 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35822?usp=email ) Change subject: pylint: transport/pcsc.py ...................................................................... pylint: transport/pcsc.py pySim/transport/pcsc.py:26:0: W0404: Reimport 'CardConnectionException' (imported line 26) (reimported) pySim/transport/pcsc.py:60:4: R1711: Useless return at end of function or method (useless-return) pySim/transport/pcsc.py:74:12: W0707: Consider explicitly re-raising using 'except CardRequestTimeoutException as exc' and 'raise NoCardError() from exc' (raise-missing-from) pySim/transport/pcsc.py:86:12: W0707: Consider explicitly re-raising using 'except CardConnectionException as exc' and 'raise ProtocolError() from exc' (raise-missing-from) pySim/transport/pcsc.py:88:12: W0707: Consider explicitly re-raising using 'except NoCardException as exc' and 'raise NoCardError() from exc' (raise-missing-from) pySim/transport/pcsc.py:22:0: W0611: Unused Union imported from typing (unused-import) Change-Id: I0ef440d8825300d6efb8959a67da095ab5623f9c --- M pySim/transport/pcsc.py 1 file changed, 24 insertions(+), 9 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index a6714d5..47976ae 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -19,11 +19,11 @@ import argparse import re -from typing import Optional, Union +from typing import Optional from smartcard.CardConnection import CardConnection from smartcard.CardRequest import CardRequest -from smartcard.Exceptions import NoCardException, CardRequestTimeoutException, CardConnectionException, CardConnectionException +from smartcard.Exceptions import NoCardException, CardRequestTimeoutException, CardConnectionException from smartcard.System import readers from pySim.exceptions import NoCardError, ProtocolError, ReaderError @@ -63,15 +63,14 @@ self._con.disconnect() except: pass - return def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False): cr = CardRequest(readers=[self._reader], timeout=timeout, newcardonly=newcardonly) try: cr.waitforcard() - except CardRequestTimeoutException: - raise NoCardError() + except CardRequestTimeoutException as exc: + raise NoCardError() from exc self.connect() def connect(self): @@ -82,10 +81,10 @@ # Explicitly select T=0 communication protocol self._con.connect(CardConnection.T0_protocol) - except CardConnectionException: - raise ProtocolError() - except NoCardException: - raise NoCardError() + except CardConnectionException as exc: + raise ProtocolError() from exc + except NoCardException as exc: + raise NoCardError() from exc def get_atr(self) -> Hexstr: return self._con.getATR() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35822?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I0ef440d8825300d6efb8959a67da095ab5623f9c Gerrit-Change-Number: 35822 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • ...
  • 175
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.