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

 (

4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted 
one.
 )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, 7 insertions(+), 3 deletions(-)

Approvals:
  fixeria: Looks good to me, approved
  Jenkins Builder: Verified




diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index c41a0b6..90d63db 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -104,6 +104,10 @@
         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: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I46b8cb81ef8cc1794c11b61e0adfb575f937b349
Gerrit-Change-Number: 37836
Gerrit-PatchSet: 5
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>

Reply via email to