From 2668eb6148aaa209f97005803823b09224f5534a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 6 Jul 2024 13:11:20 +0200 Subject: [PATCH] pySim.esim.saip: Add ProfileElementOpt{USIM,ISIM} classes Change-Id: Iebff2e767baa19f272eeddc62d7d5b3a8f665db5 --- pySim/esim/saip/__init__.py | 29 +++++++++++++++++++++++++++++ tests/test_esim_saip.py | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py index 6e17de3f..e87e5c0c 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -270,7 +270,9 @@ class ProfileElement: 'pinCodes': ProfileElementPin, 'telecom': ProfileElementTelecom, 'usim': ProfileElementUSIM, + 'opt-usim': ProfileElementOptUSIM, 'isim': ProfileElementISIM, + 'opt-isim': ProfileElementOptISIM, 'akaParameter': ProfileElementAKA, } """Construct an instance from given raw, DER encoded bytes.""" @@ -575,6 +577,19 @@ class ProfileElementUSIM(ProfileElement): f = File('ef-imsi', self.decoded['ef-imsi']) return dec_imsi(b2h(f.stream.getvalue())) +class ProfileElementOptUSIM(ProfileElement): + type = 'opt-usim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['optusim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_USIMopt_not_by_default_v2) + class ProfileElementISIM(ProfileElement): type = 'isim' @@ -594,6 +609,20 @@ class ProfileElementISIM(ProfileElement): def adf_name(self) -> str: return b2h(self.decoded['adf-isim'][0][1]['dfName']) +class ProfileElementOptISIM(ProfileElement): + type = 'opt-isim' + + def __init__(self, decoded: Optional[dict] = None): + super().__init__() + if decoded: + self.decoded = decoded + return + # provide some reasonable defaults for a MNO-SD + self.decoded = OrderedDict() + self.decoded['optisim-header'] = { 'mandated': None, 'identification': None} + self.decoded['templateID'] = str(oid.ADF_ISIMopt_not_by_default_v2) + + class ProfileElementAKA(ProfileElement): type = 'akaParameter' diff --git a/tests/test_esim_saip.py b/tests/test_esim_saip.py index 4c1b9369..5a1284e2 100755 --- a/tests/test_esim_saip.py +++ b/tests/test_esim_saip.py @@ -67,7 +67,7 @@ class SaipTest(unittest.TestCase): """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]: + ProfileElementSSD, ProfileElementOptUSIM, ProfileElementOptISIM]: with self.subTest(cls.__name__): pes = ProfileElementSequence() inst = cls()