laforge submitted this change.
pySim.esim.saip: ProfileElement{Header,End} classes
Change-Id: I88e18c1ee4907eeac3ae5d04d7bc30d6765f91fa
---
M pySim/esim/saip/__init__.py
M tests/test_esim_saip.py
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 2f69522..7dffcb2 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -22,7 +22,7 @@
import asn1tools
-from pySim.utils import bertlv_parse_tag, bertlv_parse_len, b2h, h2b, dec_imsi
+from pySim.utils import bertlv_parse_tag, bertlv_parse_len, b2h, h2b, dec_imsi, Hexstr
from pySim.ts_102_221 import FileDescriptor
from pySim.construct import build_construct
from pySim.esim import compile_asn1_subdir
@@ -187,6 +187,7 @@
# names, so we have to manually translate the exceptions here...
header_name_translation_dict = {
'header': None,
+ 'end': 'end-header',
'genericFileManagement': 'gfm-header',
'akaParameter': 'aka-header',
'cdmaParameter': 'cdma-header',
@@ -281,6 +282,8 @@
'isim': ProfileElementISIM,
'opt-isim': ProfileElementOptISIM,
'akaParameter': ProfileElementAKA,
+ 'header': ProfileElementHeader,
+ 'end': ProfileElementEnd,
}
"""Construct an instance from given raw, DER encoded bytes."""
pe_type, decoded = asn1.decode('ProfileElement', der)
@@ -676,6 +679,30 @@
'mappingSource': aid,
})
+class ProfileElementHeader(ProfileElement):
+ type = 'header'
+ def __init__(self, decoded: Optional[dict] = None,
+ ver_major: Optional[int] = 2, ver_minor: Optional[int] = 3,
+ iccid: Optional[Hexstr] = '0'*20, profile_type: Optional[str] = None):
+ super().__init__(decoded)
+ if decoded:
+ return
+ # provide some reasonable defaults
+ self.decoded = {
+ 'major-version': ver_major,
+ 'minor-version': ver_minor,
+ 'iccid': h2b(iccid),
+ 'eUICC-Mandatory-services': {}, # needs to be recomputed at the end
+ 'eUICC-Mandatory-GFSTEList': [], # needs to be recomputed at the end
+ }
+ if profile_type:
+ self.decoded['profileType'] = profile_type
+
+class ProfileElementEnd(ProfileElement):
+ type = 'end'
+ def __init__(self, decoded: Optional[dict] = None):
+ super().__init__(decoded)
+
def bertlv_first_segment(binary: bytes) -> Tuple[bytes, bytes]:
"""obtain the first segment of a binary concatenation of BER-TLV objects.
Returns: tuple of first TLV and remainder."""
diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py
index e87a073..82ed692 100755
--- a/tests/test_esim_saip.py
+++ b/tests/test_esim_saip.py
@@ -67,7 +67,8 @@
"""Test that DER-encoding of PE created by "empty" constructor works without raising exception."""
for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom,
ProfileElementUSIM, ProfileElementISIM, ProfileElementAKA, ProfileElementSD,
- ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM]:
+ ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM,
+ ProfileElementHeader, ProfileElementEnd]:
with self.subTest(cls.__name__):
pes = ProfileElementSequence()
inst = cls()
To view, visit change 37423. To unsubscribe, or for help writing mail filters, visit settings.