From 34423337608c56db3c83cda0b0c372e38aa1c01e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 22 Nov 2024 20:49:24 +0100 Subject: [PATCH] esim.saip: New methods for inserting ProfileElement into sequence ProfileElements.insert_after_pe() is a convenience method to insert a new PE after an existing one in the sequence. This is a frequent task as there are strict ordering requirements in the SAIP format. Change-Id: I4424926127b4867931c2157e9340bacd2682ff0c --- pySim/esim/saip/__init__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py index 1fcf61fc..b83367eb 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -1500,6 +1500,27 @@ class ProfileElementSequence: pe.header['identification'] = i i += 1 + def get_index_by_pe(self, pe: ProfileElement) -> int: + """Return a list with the indicies of all instances of PEs of petype.""" + ret = [] + i = 0 + for cur in self.pe_list: + if cur == pe: + return i + i += 1 + raise ValueError('PE %s is not part of PE Sequence' % (pe)) + + def insert_at_index(self, idx: int, pe: ProfileElement) -> None: + """Insert a given [new] ProfileElement at given index into the PE Sequence.""" + self.pe_list.insert(idx, pe) + self._process_pelist() + self.renumber_identification() + + def insert_after_pe(self, pe_before: ProfileElement, pe_new: ProfileElement) -> None: + """Insert a given [new] ProfileElement after a given [existing] PE in the PE Sequence.""" + idx = self.get_index_by_pe(pe_before) + self.insert_at_index(idx+1, pe_new) + def get_index_by_type(self, petype: str) -> List[int]: """Return a list with the indicies of all instances of PEs of petype.""" ret = [] @@ -1515,9 +1536,7 @@ class ProfileElementSequence: # find MNO-SD index idx = self.get_index_by_type('securityDomain')[0] # insert _after_ MNO-SD - self.pe_list.insert(idx+1, ssd) - self._process_pelist() - self.renumber_identification() + self.insert_at_index(idx+1, ssd) def remove_naas_of_type(self, naa: Naa) -> None: """Remove all instances of NAAs of given type. This can be used, for example,