laforge has submitted this change. (
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(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 90d63db..fb2097a 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: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Icd332183758b8ef20a77507b728f5e455698def0
Gerrit-Change-Number: 37837
Gerrit-PatchSet: 5
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>