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


Change subject: pySim.esim.saip: Move AKA specific post_dec + pre_enc to AKA 
subclass
......................................................................

pySim.esim.saip: Move AKA specific post_dec + pre_enc to AKA subclass

Having AKA specific code in the generic ProfileElement base class dated
back to when we didn't have a ProfileElementAKA subclass.

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



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/37/37837/1

diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 0d21499..f62fe5c 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -235,33 +235,6 @@
                 if mandated:
                     self.decoded[self.header_name] = { 'mandated': None}

-    def _fixup_sqnInit_dec(self) -> None:
-        """asn1tools has a bug when working with SEQUENCE OF that have DEFAULT 
values. Let's work around
-        this."""
-        if self.type != 'akaParameter':
-            return
-        sqn_init = self.decoded.get('sqnInit', None)
-        if not sqn_init:
-            return
-        # this weird '0x' value in a string is what we get from our (slightly 
hacked) ASN.1 syntax
-        if sqn_init == '0x000000000000':
-            # SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6))
-            self.decoded['sqnInit'] = [b'\x00'*6] * 32
-
-    def _fixup_sqnInit_enc(self) -> None:
-        """asn1tools has a bug when working with SEQUENCE OF that have DEFAULT 
values. Let's work around
-        this."""
-        if self.type != 'akaParameter':
-            return
-        sqn_init = self.decoded.get('sqnInit', None)
-        if not sqn_init:
-            return
-        for s in sqn_init:
-            if any(s):
-                return
-        # none of the fields were initialized with a non-default (non-zero) 
value, so we can skip it
-        del self.decoded['sqnInit']
-
     @property
     def header_name(self) -> str:
         """Return the name of the header field within the profile element."""
@@ -337,8 +310,6 @@
         else:
             inst = ProfileElement(decoded)
             inst.type = pe_type
-        # work around asn1tools bug regarding DEFAULT for a SEQUENCE OF
-        inst._fixup_sqnInit_dec()
         # run any post-decoder a derived class may have
         if hasattr(inst, '_post_decode'):
             inst._post_decode()
@@ -349,8 +320,6 @@
         # run any pre-encoder a derived class may have
         if hasattr(self, '_pre_encode'):
             self._pre_encode()
-        # work around asn1tools bug regarding DEFAULT for a SEQUENCE OF
-        self._fixup_sqnInit_enc()
         return asn1.encode('ProfileElement', (self.type, self.decoded))

     def __str__(self) -> str:
@@ -861,6 +830,37 @@
         # provide some reasonable defaults for a MNO-SD
         self.set_milenage(b'\x00'*16, b'\x00'*16)

+    def _fixup_sqnInit_dec(self) -> None:
+        """asn1tools has a bug when working with SEQUENCE OF that have DEFAULT 
values. Let's work around
+        this."""
+        sqn_init = self.decoded.get('sqnInit', None)
+        if not sqn_init:
+            return
+        # this weird '0x' value in a string is what we get from our (slightly 
hacked) ASN.1 syntax
+        if sqn_init == '0x000000000000':
+            # SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6))
+            self.decoded['sqnInit'] = [b'\x00'*6] * 32
+
+    def _fixup_sqnInit_enc(self) -> None:
+        """asn1tools has a bug when working with SEQUENCE OF that have DEFAULT 
values. Let's work around
+        this."""
+        sqn_init = self.decoded.get('sqnInit', None)
+        if not sqn_init:
+            return
+        for s in sqn_init:
+            if any(s):
+                return
+        # none of the fields were initialized with a non-default (non-zero) 
value, so we can skip it
+        del self.decoded['sqnInit']
+
+    def _post_decode(self):
+        # work around asn1tools bug regarding DEFAULT for a SEQUENCE OF
+        self._fixup_sqnInit_dec()
+
+    def _pre_encode(self):
+        # work around asn1tools bug regarding DEFAULT for a SEQUENCE OF
+        self._fixup_sqnInit_enc()
+
     def set_milenage(self, k: bytes, opc: bytes):
         """Configure akaParametes for MILENAGE."""
         self.decoded['algoConfiguration'] = ('algoParameter', {

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

Reply via email to