laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37836?usp=email )


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

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

Change-Id: I46b8cb81ef8cc1794c11b61e0adfb575f937b349
---
M pySim/esim/saip/__init__.py
1 file changed, 8 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/36/37836/1

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 0bf805d..0d21499 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -97,13 +97,17 @@
         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)
         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 @@
             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 @@
             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'

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37836?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: I46b8cb81ef8cc1794c11b61e0adfb575f937b349
Gerrit-Change-Number: 37836
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>

Reply via email to