pySim.esim.saip: Refactor file size encoding into a method

Change-Id: I46b8cb81ef8cc1794c11b61e0adfb575f937b349
This commit is contained in:
Harald Welte
2024-08-06 11:33:58 +02:00
parent 6d495fb24d
commit 31c3c9a1e3

View File

@@ -104,6 +104,10 @@ class File:
if l:
self.from_tuples(l)
def _encode_file_size(self, size: int) -> bytes:
# FIXME: handle > v2.0 case where it must be encoded on the minimum number of octets possible
return size.to_bytes(2, 'big')
def from_template(self, template: templates.FileTemplate):
"""Determine defaults for file based on given FileTemplate."""
fdb_dec = {}
@@ -122,7 +126,7 @@ class File:
if template.rec_len:
self.record_len = template.rec_len
if template.nb_rec and template.rec_len:
self.fileDescriptor['efFileSize'] = (template.nb_rec * template.rec_len).to_bytes(2, 'big') # FIXME
self.fileDescriptor['efFileSize'] = self._encode_file_size(template.nb_rec * template.rec_len)
if template.file_type == 'LF':
fdb_dec['structure'] = 'linear_fixed'
elif template.file_type == 'CY':
@@ -131,12 +135,12 @@ class File:
fdb_dec['file_type'] = 'working_ef'
fdb_dec['structure'] = 'ber_tlv'
if template.file_size:
pefi['maximumFileSize'] = template.file_size.to_bytes(2, 'big') # FIXME
pefi['maximumFileSize'] = self._encode_file_size(template.file_size)
elif template.file_type == 'TR':
fdb_dec['file_type'] = 'working_ef'
fdb_dec['structure'] = 'transparent'
if template.file_size:
self.fileDescriptor['efFileSize'] = template.file_size.to_bytes(2, 'big') # FIXME
self.fileDescriptor['efFileSize'] = self._encode_file_size(template.file_size)
elif template.file_type in ['MF', 'DF', 'ADF']:
fdb_dec['file_type'] = 'df'
fdb_dec['structure'] = 'no_info_given'