laforge has submitted this change. (
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(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
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: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1a908504b845b7c90f31294faf2a6e988bdd8049
Gerrit-Change-Number: 38906
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>