mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 08:18:36 +03:00
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
This commit is contained in:
@@ -97,7 +97,7 @@ class File:
|
|||||||
self.pe_name = pename
|
self.pe_name = pename
|
||||||
self.template = template
|
self.template = template
|
||||||
self.fileDescriptor = {}
|
self.fileDescriptor = {}
|
||||||
self.stream = None
|
self.body = None
|
||||||
# apply some defaults from profile
|
# apply some defaults from profile
|
||||||
if self.template:
|
if self.template:
|
||||||
self.from_template(self.template)
|
self.from_template(self.template)
|
||||||
@@ -173,7 +173,7 @@ class File:
|
|||||||
raise ValueError("No fileDescriptor found in tuple, and none set by template before")
|
raise ValueError("No fileDescriptor found in tuple, and none set by template before")
|
||||||
if fd:
|
if fd:
|
||||||
self.fileDescriptor.update(dict(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):
|
def from_gfm(self, d: Dict):
|
||||||
print(d)
|
print(d)
|
||||||
@@ -184,7 +184,7 @@ class File:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@staticmethod
|
@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."""
|
"""linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes."""
|
||||||
stream = io.BytesIO()
|
stream = io.BytesIO()
|
||||||
for k, v in l:
|
for k, v in l:
|
||||||
@@ -199,7 +199,14 @@ class File:
|
|||||||
stream.write(v)
|
stream.write(v)
|
||||||
else:
|
else:
|
||||||
return ValueError("Unknown key '%s' in tuple list" % k)
|
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:
|
def __str__(self) -> str:
|
||||||
return "File(%s)" % self.pe_name
|
return "File(%s)" % self.pe_name
|
||||||
@@ -819,7 +826,7 @@ class ProfileElementUSIM(FsProfileElement):
|
|||||||
@property
|
@property
|
||||||
def imsi(self) -> Optional[str]:
|
def imsi(self) -> Optional[str]:
|
||||||
f = File('ef-imsi', self.decoded['ef-imsi'])
|
f = File('ef-imsi', self.decoded['ef-imsi'])
|
||||||
return dec_imsi(b2h(f.stream.getvalue()))
|
return dec_imsi(b2h(f.body))
|
||||||
|
|
||||||
class ProfileElementOptUSIM(FsProfileElement):
|
class ProfileElementOptUSIM(FsProfileElement):
|
||||||
type = 'opt-usim'
|
type = 'opt-usim'
|
||||||
|
|||||||
Reference in New Issue
Block a user