laforge submitted this change.

View Change

Approvals: Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve laforge: Looks good to me, approved
pySim.esim.saip.File: move away from stream for file content

Let's linearize the file content in a bytes member variable self.body.

Change-Id: I6cb23a3a644854abd3dfd3b50b586ce80da21353
---
M pySim/esim/saip/__init__.py
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 20e2cb4..27327b0 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -97,7 +97,7 @@
self.pe_name = pename
self.template = template
self.fileDescriptor = {}
- self.stream = None
+ self.body = None
# apply some defaults from profile
if self.template:
self.from_template(self.template)
@@ -173,7 +173,7 @@
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)
+ self.body = self.linearize_file_content(l)

def from_gfm(self, d: Dict):
print(d)
@@ -184,7 +184,7 @@
raise NotImplementedError

@staticmethod
- def linearize_file_content(l: List[Tuple]) -> Optional[io.BytesIO]:
+ def linearize_file_content(l: List[Tuple]) -> Optional[bytes]:
"""linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes."""
stream = io.BytesIO()
for k, v in l:
@@ -199,7 +199,14 @@
stream.write(v)
else:
return ValueError("Unknown key '%s' in tuple list" % k)
- return stream
+ return stream.getvalue()
+
+ def file_content_to_tuples(self) -> List[Tuple]:
+ # FIXME: simplistic approach. needs optimization. We should first check if the content
+ # matches the expanded default value from the template. If it does, return empty list.
+ # Next, we should compute the diff between the default value and self.body, and encode
+ # that as a sequence of fillFileOffset and fillFileContent tuples.
+ return [('fillFileContent', self.body)]

def __str__(self) -> str:
return "File(%s)" % self.pe_name
@@ -819,7 +826,7 @@
@property
def imsi(self) -> Optional[str]:
f = File('ef-imsi', self.decoded['ef-imsi'])
- return dec_imsi(b2h(f.stream.getvalue()))
+ return dec_imsi(b2h(f.body))

class ProfileElementOptUSIM(FsProfileElement):
type = 'opt-usim'

To view, visit change 37847. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I6cb23a3a644854abd3dfd3b50b586ce80da21353
Gerrit-Change-Number: 37847
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>