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

July 2024

  • 1 participants
  • 1379 discussions
[S] Change in pysim[master]: pySim-shell: fix reset command
by dexter 26 Jul '24

26 Jul '24
Attention is currently required from: laforge. dexter has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/37614?usp=email ) Change subject: pySim-shell: fix reset command ...................................................................... Patch Set 2: (1 comment) File pySim/runtime.py: https://gerrit.osmocom.org/c/pysim/+/37614/comment/b8ca1b7b_4d654686 PS1, Line 142: if (cmd_app): > python uses no parenthesis around an if statement Done -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37614?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: I1ad29c9e7ce7d80bebc92fa173ed7a44ee4c2998 Gerrit-Change-Number: 37614 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Fri, 26 Jul 2024 08:35:53 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge <laforge(a)osmocom.org> Gerrit-MessageType: comment
1 0
0 0
[S] Change in pysim[master]: pySim-shell: fix reset command
by dexter 26 Jul '24

26 Jul '24
Attention is currently required from: laforge. Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/37614?usp=email to look at the new patch set (#2). The following approvals got outdated and were removed: Verified-1 by Jenkins Builder Change subject: pySim-shell: fix reset command ...................................................................... pySim-shell: fix reset command The reset command resets the card using the card object. This unfortunately leaves the RuntimeState uninformed about the event. However, the RuntimeState class also has a reset method that resets the card and the RuntimeState. Let's use this reset method. Also fix this method so that it ensures that the SCP is also no longer present. Related: OS#6092 Change-Id: I1ad29c9e7ce7d80bebc92fa173ed7a44ee4c2998 --- M pySim-shell.py M pySim/runtime.py 2 files changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/14/37614/2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37614?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: I1ad29c9e7ce7d80bebc92fa173ed7a44ee4c2998 Gerrit-Change-Number: 37614 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newpatchset
1 0
0 0
[M] Change in pysim[master]: pySim-shell: move export code into filesystem class model
by dexter 26 Jul '24

26 Jul '24
Attention is currently required from: dexter, laforge. Hello Jenkins Builder, laforge, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/37612?usp=email to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review+1 by laforge, Verified-1 by Jenkins Builder Change subject: pySim-shell: move export code into filesystem class model ...................................................................... pySim-shell: move export code into filesystem class model The code that generates the filesystem export lines for the various different file structures can be moved into the filesystem class model. This simplifies the code since we do not need any extra logic to distinguish between the different file structures. Related: OS#6092 Change-Id: Icc2ee60cfc4379411744ca1033d79a1ee9cff5a6 --- M pySim-shell.py M pySim/filesystem.py 2 files changed, 119 insertions(+), 58 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/12/37612/2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37612?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: Icc2ee60cfc4379411744ca1033d79a1ee9cff5a6 Gerrit-Change-Number: 37612 Gerrit-PatchSet: 2 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-MessageType: newpatchset
1 0
0 0
[S] Change in pysim[master]: Revert "tlv: Fix from_dict() symmetry"
by laforge 26 Jul '24

26 Jul '24
Attention is currently required from: dexter, lynxis lazus. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/36127?usp=email ) Change subject: Revert "tlv: Fix from_dict() symmetry" ...................................................................... Patch Set 1: Code-Review-2 (1 comment) Patchset: PS1: For a proper fix that doesn't break all other users of from_dict see https://gerrit.osmocom.org/c/pysim/+/37623 https://gerrit.osmocom.org/c/pysim/+/37624 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/36127?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: I1710bf9124acf7952d3231b104407e9ac998d6a8 Gerrit-Change-Number: 36127 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Fri, 26 Jul 2024 07:03:43 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in pysim[master]: ara_m: Fix pySim.tlv.IE.from_dict() calls
by laforge 26 Jul '24

26 Jul '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/37624?usp=email ) Change subject: ara_m: Fix pySim.tlv.IE.from_dict() calls ...................................................................... ara_m: Fix pySim.tlv.IE.from_dict() calls Historically, to_dict and from_dict were not symmetric; this has been fixed in I07e4feb3800b420d8be7aae8911f828f1da9dab8 in December 2023. This however broke the ara_m legacy use of the from_dict() methods. We've just introduced a from_val_dict() method in I81654ea54aed9e598943f41a26a57dcc3a7f10c2, let's make use of it. Change-Id: I3aaec40eb665d6254be7b103444c04ff48aac36d --- M pySim/ara_m.py 1 file changed, 19 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/24/37624/1 diff --git a/pySim/ara_m.py b/pySim/ara_m.py index 5776e3d..5d0f35d 100644 --- a/pySim/ara_m.py +++ b/pySim/ara_m.py @@ -298,8 +298,8 @@ @staticmethod def get_config(tp, v_major=0, v_minor=0, v_patch=1): cmd_do = DeviceConfigDO() - cmd_do.from_dict([{'device_interface_version_do': { - 'major': v_major, 'minor': v_minor, 'patch': v_patch}}]) + cmd_do.from_val_dict([{'device_interface_version_do': { + 'major': v_major, 'minor': v_minor, 'patch': v_patch}}]) return ADF_ARAM.xceive_apdu_tlv(tp, '80cadf21', cmd_do, ResponseAramConfigDO) @with_default_category('Application-Specific Commands') @@ -372,7 +372,7 @@ ar_do_content += [{'perm_ar_do': {'permissions': opts.android_permissions}}] d = [{'ref_ar_do': [{'ref_do': ref_do_content}, {'ar_do': ar_do_content}]}] csrado = CommandStoreRefArDO() - csrado.from_dict(d) + csrado.from_val_dict(d) res_do = ADF_ARAM.store_data(self._cmd.lchan.scc._tp, csrado) if res_do: self._cmd.poutput_json(res_do.to_dict()) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37624?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: I3aaec40eb665d6254be7b103444c04ff48aac36d Gerrit-Change-Number: 37624 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in pysim[master]: pySim.tlv: Separate {to,from}_val_dict() from {to,from}_dict()
by laforge 26 Jul '24

26 Jul '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/37623?usp=email ) Change subject: pySim.tlv: Separate {to,from}_val_dict() from {to,from}_dict() ...................................................................... pySim.tlv: Separate {to,from}_val_dict() from {to,from}_dict() There are some situations where we want to work with a type-name-wrapped dict that includes the type information, and others where we don't want that. The main reason is that nested IEs can only be reconstructed if we can determine the type/class of the nested IE from the dict data. Let's explicitly offer {to,from}_val_dict() methods that work with the value-part only Related: OS#6453 Change-Id: I81654ea54aed9e598943f41a26a57dcc3a7f10c2 --- M pySim/tlv.py 1 file changed, 47 insertions(+), 11 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/23/37623/1 diff --git a/pySim/tlv.py b/pySim/tlv.py index 4d542da..7207eaf 100644 --- a/pySim/tlv.py +++ b/pySim/tlv.py @@ -142,25 +142,43 @@ else: return '%s(%s)' % (type(self).__name__, self.decoded) - def to_dict(self): - """Return a JSON-serializable dict representing the [nested] IE data.""" + def to_val_dict(self): + """Return a JSON-serializable dict representing just the [nested] value portion of the IE + data. This does not include any indication of the type of 'self', so the resulting dict alone + will be insufficient ot recreate an object from it without additional type information.""" if len(self.children): - v = [x.to_dict() for x in self.children] + return [x.to_dict() for x in self.children] else: - v = self.decoded - return {camel_to_snake(type(self).__name__): v} + return self.decoded + + def from_val_dict(self, decoded): + """Set the IE internal decoded representation to data from the argument. + If this is a nested IE, the child IE instance list is re-created. + + This method is symmetrical to to_val_dict() aboe, i.e. there is no outer dict + containig the snake-reformatted type name of 'self'.""" + if self.nested_collection: + self.children = self.nested_collection.from_dict(decoded) + else: + self.children = [] + self.decoded = decoded + + def to_dict(self): + """Return a JSON-serializable dict representing the [nested] IE data. The returned + data contains an outer dict with the snake-reformatted type of 'self' and is hence + sufficient to re-create an object from it.""" + return {camel_to_snake(type(self).__name__): self.to_val_dict()} def from_dict(self, decoded: dict): """Set the IE internal decoded representation to data from the argument. - If this is a nested IE, the child IE instance list is re-created.""" + If this is a nested IE, the child IE instance list is re-created. + + This method is symmetrical to to_dict() above, i.e. the outer dict must contain just a single + key-value pair, where the key is the snake-reformatted type name of 'self'""" expected_key_name = camel_to_snake(type(self).__name__) if not expected_key_name in decoded: raise ValueError("Dict %s doesn't contain expected key %s" % (decoded, expected_key_name)) - if self.nested_collection: - self.children = self.nested_collection.from_dict(decoded[expected_key_name]) - else: - self.children = [] - self.decoded = decoded[expected_key_name] + self.from_val_dict(decoded[expected_key_name]) def is_constructed(self): """Is this IE constructed by further nested IEs?""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37623?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: I81654ea54aed9e598943f41a26a57dcc3a7f10c2 Gerrit-Change-Number: 37623 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: Revert "tlv: Fix from_dict() symmetry"
by laforge 26 Jul '24

26 Jul '24
Attention is currently required from: dexter, lynxis lazus. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/36127?usp=email ) Change subject: Revert "tlv: Fix from_dict() symmetry" ...................................................................... Patch Set 1: (1 comment) Patchset: PS1: > I have tried this and I can confirm that this fixes the problem with the ARA-M interface. I have never argued that this patch fixes one specific problem. But I'm also sure it introduces tons of problems elsewhere at the same time 😊 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/36127?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: I1710bf9124acf7952d3231b104407e9ac998d6a8 Gerrit-Change-Number: 36127 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Fri, 26 Jul 2024 06:42:03 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: dexter <pmaier(a)sysmocom.de> Gerrit-MessageType: comment
1 0
0 0
[M] Change in pysim[master]: pySim.esim.saip: Decode each 'File' element in ProfileElement
by laforge 26 Jul '24

26 Jul '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/37619?usp=email ) Change subject: pySim.esim.saip: Decode each 'File' element in ProfileElement ...................................................................... pySim.esim.saip: Decode each 'File' element in ProfileElement When loading a ProfileElement from its DER-ecoded format, populate a dict with a pySim.esim.saip.File object for each file. Change-Id: Ie2791c10289eb28daed2904467b0c5e5b11c94c2 --- M pySim/esim/saip/__init__.py 1 file changed, 59 insertions(+), 16 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/19/37619/1 diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py index abaa679..c76cb5c 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -147,9 +147,10 @@ if k == 'fileDescriptor': return v fd = get_fileDescriptor(l) - if not fd: - raise ValueError("No fileDescriptor found") - self.fileDescriptor.update(dict(fd)) + if not fd and not self.fileDescriptor: + raise ValueError("No fileDescriptor found in tuple, and none set by template before") + if fd: + self.fileDescriptor.update(dict(fd)) self.stream = self.linearize_file_content(l) def to_tuples(self) -> List[Tuple]: @@ -262,13 +263,6 @@ """Return the decoded templateID used by this profile element (if any).""" return self.decoded.get('templateID', None) - @property - def files(self): - """Return dict of decoded 'File' ASN.1 items.""" - if not self.type in self.FILE_BEARING: - return {} - return {k:v for (k,v) in self.decoded.items() if k not in ['templateID', self.header_name]} - @classmethod def from_der(cls, der: bytes) -> 'ProfileElement': class4petype = { @@ -311,7 +305,44 @@ def __str__(self) -> str: return self.type -class ProfileElementMF(ProfileElement): +class FsProfileElement(ProfileElement): + """A file-system bearing profile element, like MF, USIM, ....""" + + def __init__(self, decoded = None, mandated: bool = True): + super().__init__(decoded, mandated) + # indexed by PE-Name + self.files = {} + self.tdef = asn1.types['ProfileElement'].type.name_to_member[self.type] + + def add_file(self, file: File): + """Add a File to the ProfileElement.""" + if file.pe_name in self.files: + raise KeyError('Cannot add file: %s already exists' % file.pename) + self.files[file.pe_name] = file + + def files2pe(self): + """Update the "decoded" member with the contents of the files member.""" + for f in self.files: + self.decoded[f.pename] = f.to_tuples() + + def pe2files(self): + """Update the "files" member with the contents of the "decoded" member.""" + tdict = {x.name: x for x in self.tdef.root_members} + template = templates.ProfileTemplateRegistry.get_by_oid(self.templateID) + for k, v in self.decoded.items(): + if tdict[k].type_name == 'File': + self.add_file(File(k, v, template.files_by_pename.get(k, None))) + + def _post_decode(self): + # not entirely sure about this automatism + self.pe2files() + + def _pre_encode(self): + # should we do self.pe2files()? I don't think so + #self.files2pe() + pass + +class ProfileElementMF(FsProfileElement): type = 'mf' def __init__(self, decoded: Optional[dict] = None): @@ -390,7 +421,7 @@ self.decoded['pinCodes'][1].append(pin) -class ProfileElementTelecom(ProfileElement): +class ProfileElementTelecom(FsProfileElement): type = 'telecom' def __init__(self, decoded: Optional[dict] = None): @@ -576,7 +607,7 @@ 'adfAdminAccessDomain': ADM1_ACCESS, } -class ProfileElementUSIM(ProfileElement): +class ProfileElementUSIM(FsProfileElement): type = 'usim' def __init__(self, decoded: Optional[dict] = None): @@ -597,7 +628,7 @@ f = File('ef-imsi', self.decoded['ef-imsi']) return dec_imsi(b2h(f.stream.getvalue())) -class ProfileElementOptUSIM(ProfileElement): +class ProfileElementOptUSIM(FsProfileElement): type = 'opt-usim' def __init__(self, decoded: Optional[dict] = None): @@ -607,7 +638,7 @@ # provide some reasonable defaults for a MNO-SD self.decoded['templateID'] = str(oid.ADF_USIMopt_not_by_default_v2) -class ProfileElementISIM(ProfileElement): +class ProfileElementISIM(FsProfileElement): type = 'isim' def __init__(self, decoded: Optional[dict] = None): @@ -623,7 +654,7 @@ def adf_name(self) -> str: return b2h(self.decoded['adf-isim'][0][1]['dfName']) -class ProfileElementOptISIM(ProfileElement): +class ProfileElementOptISIM(FsProfileElement): type = 'opt-isim' def __init__(self, decoded: Optional[dict] = None): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37619?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: Ie2791c10289eb28daed2904467b0c5e5b11c94c2 Gerrit-Change-Number: 37619 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: saip-tool: Fix TAR display for implicit TAR
by laforge 26 Jul '24

26 Jul '24
Attention is currently required from: laforge. Hello Jenkins Builder, dexter, fixeria, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/37541?usp=email to look at the new patch set (#3). The following approvals got outdated and were removed: Verified+1 by Jenkins Builder The change is no longer submittable: Verified is unsatisfied now. Change subject: saip-tool: Fix TAR display for implicit TAR ...................................................................... saip-tool: Fix TAR display for implicit TAR Until Change-Id Ifba1048e3000829d54769b0420f5134e2f9b04e1 the TAR output was working for implicit tar. With said commit we fixed it for explicit tar but broke implicit tar. With this commit it works for both implicit and explicit TAR. Change-Id: I76133b0e02996a138257f3fba5ceb0d2fc6fad80 --- M contrib/saip-tool.py 1 file changed, 17 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/41/37541/3 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37541?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: I76133b0e02996a138257f3fba5ceb0d2fc6fad80 Gerrit-Change-Number: 37541 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newpatchset
1 0
0 0
[M] Change in pysim[master]: pySim.esim.saip: Add OID comparison functions
by laforge 26 Jul '24

26 Jul '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/37618?usp=email ) Change subject: pySim.esim.saip: Add OID comparison functions ...................................................................... pySim.esim.saip: Add OID comparison functions Change-Id: Iab642e0cc6597f667ea126827ea888652f0f2689 --- M pySim/esim/saip/oid.py M tests/test_esim_saip.py 2 files changed, 54 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/18/37618/1 diff --git a/pySim/esim/saip/oid.py b/pySim/esim/saip/oid.py index 91a48c1..6828e81 100644 --- a/pySim/esim/saip/oid.py +++ b/pySim/esim/saip/oid.py @@ -15,8 +15,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from functools import total_ordering from typing import List, Union +@total_ordering class OID: @staticmethod def intlist_from_str(instr: str) -> List[int]: @@ -26,6 +28,10 @@ def str_from_intlist(intlist: List[int]) -> str: return '.'.join([str(x) for x in intlist]) + @staticmethod + def highest_oid(oids: List['OID']) -> 'OID': + return sorted(oids)[-1] + def __init__(self, initializer: Union[List[int], str]): if isinstance(initializer, str): self.intlist = self.intlist_from_str(initializer) @@ -38,6 +44,39 @@ def __repr__(self) -> str: return 'OID(%s)' % (str(self)) + def __eq__(self, other: 'OID'): + return (self.intlist == other.intlist) + + def __ne__(self, other: 'OID'): + # implement based on __eq__ + return not (self == other) + + def cmp(self, other: 'OID'): + self_len = len(self.intlist) + other_len = len(other.intlist) + common_len = min(self_len, other_len) + max_len = max(self_len, other_len) + + for i in range(0, max_len+1): + if i >= self_len: + # other list is longer + return -1 + if i >= other_len: + # our list is longer + return 1 + if self.intlist[i] > other.intlist[i]: + # our version is higher + return 1 + if self.intlist[i] < other.intlist[i]: + # other version is higher + return -1 + # continue to next digit + return 0 + + def __gt__(self, other: 'OID'): + if self.cmp(other) > 0: + return True + def prefix_match(self, oid_str): """determine if oid_str is equal or below our OID.""" return oid_str.startswith(str(self)) diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index 82ed692..dcde1b4 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -83,6 +83,12 @@ pes.append(inst) pes.to_der() +class OidTest(unittest.TestCase): + def test_cmp(self): + self.assertTrue(oid.OID('1.0') > oid.OID('0.9')) + self.assertTrue(oid.OID('1.0') == oid.OID('1.0')) + self.assertTrue(oid.OID('1.0.1') > oid.OID('1.0')) + self.assertTrue(oid.OID('1.0.2') > oid.OID('1.0.1')) if __name__ == "__main__": unittest.main() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37618?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: Iab642e0cc6597f667ea126827ea888652f0f2689 Gerrit-Change-Number: 37618 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • ...
  • 138
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.