Attention is currently required from: dexter, laforge.
fixeria has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/pysim/+/38896?usp=email )
Change subject: pySim.esim.saip: Treat "Readable and Updateable when deactivated" flag
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38896?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7644d265f746c662b64f7156b3be08a01e3a97aa
Gerrit-Change-Number: 38896
Gerrit-PatchSet: 1
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-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Fri, 22 Nov 2024 21:06:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38905?usp=email )
Change subject: esim.saip: New methods for inserting ProfileElement into sequence
......................................................................
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
---
M pySim/esim/saip/__init__.py
1 file changed, 22 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/05/38905/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 1fcf61f..b83367e 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -1500,6 +1500,27 @@
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 @@
# 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,
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38905?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4424926127b4867931c2157e9340bacd2682ff0c
Gerrit-Change-Number: 38905
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38906?usp=email )
Change subject: esim.saip.File: Re-compute file_size when changing body
......................................................................
esim.saip.File: Re-compute file_size when changing body
If the API user modifies the size of the body, we need to check if we
need to re-compute the file_size attribute which is later encoded into
the fileDescriptor. The size obviously must be large enough to fit the
body. Let's do this implicitly by introducing a setter for File.body
Change-Id: I1a908504b845b7c90f31294faf2a6e988bdd8049
---
M pySim/esim/saip/__init__.py
1 file changed, 20 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/06/38906/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index b83367e..163c91b 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -106,7 +106,7 @@
self.pe_name = pename
self._name = name
self.template = template
- self.body: Optional[bytes] = None
+ self._body: Optional[bytes] = None
self.node: Optional['FsNode'] = None
self.file_type = None
self.fid: Optional[int] = None
@@ -191,6 +191,24 @@
# All the files defined in the templates shall have, by default, shareable/not-shareable bit in the file descriptor set to "shareable".
self.shareable = True
self._template_derived = True
+ if hasattr(template, 'file_size'):
+ self._file_size = template.file_size
+
+ def _recompute_size(self):
+ """recompute the file size, if needed (body larger than current size)"""
+ body_size = len(self.body)
+ if self.file_size == None or self.file_size < body_size:
+ self._file_size = body_size
+
+ @property
+ def body(self):
+ return self._body
+
+ @body.setter
+ def body(self, value: bytes):
+ self._body = value
+ # we need to potentially update the file size after changing the body [size]
+ self._recompute_size()
def to_fileDescriptor(self) -> dict:
"""Convert from internal representation to 'fileDescriptor' as used by asn1tools for SAIP"""
@@ -332,7 +350,7 @@
if fd:
self.from_fileDescriptor(dict(fd))
# BODY
- self.body = self.file_content_from_tuples(l)
+ self._body = self.file_content_from_tuples(l)
@staticmethod
def path_from_gfm(bin_path: bytes):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38906?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1a908504b845b7c90f31294faf2a6e988bdd8049
Gerrit-Change-Number: 38906
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38907?usp=email )
Change subject: esim.saip.File: Proper ARR conversion of template (into) to file (bytes)
......................................................................
esim.saip.File: Proper ARR conversion of template (into) to file (bytes)
The encoding of the access rule reference is different in FileTemplate
vs File, let's make sure we properly convert it when instantiating a
File from a FileTemplate.
Change-Id: Ibb8afb85cc0006bc5c59230ebf28b2c0c1a8a8ed
---
M pySim/esim/saip/__init__.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/07/38907/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 163c91b..40ef4ce 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -178,7 +178,7 @@
self.file_type = template.file_type
self.fid = template.fid
self.sfi = template.sfi
- self.arr = template.arr
+ self.arr = template.arr.to_bytes(1)
if hasattr(template, 'rec_len'):
self.rec_len = template.rec_len
else:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38907?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ibb8afb85cc0006bc5c59230ebf28b2c0c1a8a8ed
Gerrit-Change-Number: 38907
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38908?usp=email )
Change subject: esim.saip.File: Suppress encoding attributes that are like template
......................................................................
esim.saip.File: Suppress encoding attributes that are like template
The point of the SAIP template mechanism is to reduce the size of the
encoded profile. Therefore, our encoder in the to_fileDescriptor()
method should suppress generating attributes if their value is identical
to that of the template (if any).
Change-Id: I337ee6c7e882ec711bece17b7a0def9da36b0ad7
---
M pySim/esim/saip/__init__.py
1 file changed, 3 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/08/38908/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 40ef4ce..94df453 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -216,13 +216,13 @@
fdb_dec = {}
pefi = {}
spfi = 0
- if self.fid:
+ if self.fid and self.fid != self.template.fid:
fileDescriptor['fileID'] = self.fid.to_bytes(2, 'big')
- if self.sfi:
+ if self.sfi and self.sfi != self.template.sfi:
fileDescriptor['shortEFID'] = bytes([self.sfi])
if self.df_name:
fileDescriptor['dfName'] = self.df_name
- if self.arr:
+ if self.arr and self.arr != self.template.arr.to_bytes(1):
fileDescriptor['securityAttributesReferenced'] = self.arr
if self.file_type in ['LF', 'CY']:
fdb_dec['file_type'] = 'working_ef'
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38908?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I337ee6c7e882ec711bece17b7a0def9da36b0ad7
Gerrit-Change-Number: 38908
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38909?usp=email )
Change subject: esim.saip.FsProfileElement: Add create_file() method
......................................................................
esim.saip.FsProfileElement: Add create_file() method
So far we mainly created File() instances when parsing existing
profiles. However, sometimes we want to programmatically create Files
and we should offer a convenience helper to do so, rather than asking
API users to worry about low-level details.
Change-Id: I0817819af40f3d0dc0c3d2b91039c5748dd31ee2
---
M pySim/esim/saip/__init__.py
1 file changed, 8 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/09/38909/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 94df453..2552c8e 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -643,6 +643,14 @@
file = File(k, v, template.files_by_pename.get(k, None))
self.add_file(file)
+ def create_file(self, pename: str) -> File:
+ """Programatically create a file by its PE-Name."""
+ template = templates.ProfileTemplateRegistry.get_by_oid(self.templateID)
+ file = File(pename, None, template.files_by_pename.get(pename, None))
+ self.add_file(file)
+ self.decoded[pename] = []
+ return file
+
def _post_decode(self):
# not entirely sure about doing this this automatism
self.pe2files()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38909?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I0817819af40f3d0dc0c3d2b91039c5748dd31ee2
Gerrit-Change-Number: 38909
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>