laforge has uploaded this change for review.

View Change

pySim.esim.saip: pass up **kwargs from ProfileElement sub-class constructors

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

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/43/37843/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 65396b1..25d5b6b 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -344,12 +344,19 @@
return self.type

class FsProfileElement(ProfileElement):
- """A file-system bearing profile element, like MF, USIM, ...."""
+ """A file-system bearing profile element, like MF, USIM, ....

- def __init__(self, decoded = None, mandated: bool = True):
- super().__init__(decoded, mandated)
+ We keep two major representations of the data:
+ * The "decoded" member, as introduced by our parent class, containing asn1tools syntax
+ * the "files" dict, consisting of File values indexed by PE-name strings
+
+ The methods pe2files and files2pe convert between those two representations.
+ """
+ def __init__(self, decoded = None, mandated: bool = True, **kwargs):
+ super().__init__(decoded, mandated, **kwargs)
# indexed by PE-Name
self.files = {}
+ # resolve ASN.1 type definition; needed to e.g. iterate field names (for file pe-names)
self.tdef = asn1.types['ProfileElement'].type.name_to_member[self.type]

def add_file(self, file: File):
@@ -383,8 +390,12 @@
class ProfileElementGFM(ProfileElement):
type = 'genericFileManagement'

- def __init__(self, decoded = None, mandated: bool = True):
- super().__init__(decoded, mandated)
+ @staticmethod
+ def path_str(path: List[int]) -> str:
+ return '/'.join(['%04X' % x for x in path])
+
+ def __init__(self, decoded = None, mandated: bool = True, **kwargs):
+ super().__init__(decoded, mandated, **kwargs)
# indexed by PE-Name
self.files = {}
self.tdef = asn1.types['ProfileElement'].type.name_to_member[self.type]
@@ -434,8 +445,8 @@
class ProfileElementMF(FsProfileElement):
type = 'mf'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -447,8 +458,8 @@
class ProfileElementPuk(ProfileElement):
type = 'pukCodes'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -477,8 +488,8 @@
class ProfileElementPin(ProfileElement):
type = 'pinCodes'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -513,8 +524,8 @@
class ProfileElementTelecom(FsProfileElement):
type = 'telecom'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -525,8 +536,8 @@
class ProfileElementPhonebook(FsProfileElement):
type = 'phonebook'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -537,8 +548,8 @@
class ProfileElementGsmAccess(FsProfileElement):
type = 'gsm-access'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -549,8 +560,8 @@
class ProfileElementDf5GS(FsProfileElement):
type = 'df-5gs'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -561,8 +572,8 @@
class ProfileElementEAP(FsProfileElement):
type = 'eap'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -573,8 +584,8 @@
class ProfileElementDfSAIP(FsProfileElement):
type = 'df-saip'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -585,8 +596,8 @@
class ProfileElementDfSNPN(FsProfileElement):
type = 'df-snpn'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -597,8 +608,8 @@
class ProfileElementDf5GProSe(FsProfileElement):
type = 'df-5gprose'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -668,8 +679,8 @@
class C9(BER_TLV_IE, tag=0xC9, nested=UiccSdInstallParams):
pass

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -743,8 +754,8 @@

class ProfileElementSSD(ProfileElementSD):
"""Class representing a securityDomain ProfileElement for a SSD."""
- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# defaults [overriding ProfileElementSD) taken from SAIP v2.3.1 Section 11.2.12
@@ -761,8 +772,8 @@
def __init__(self, decoded: Optional[dict] = None,
inst_aid: Optional[bytes] = None, sd_aid: Optional[bytes] = None,
adf_aid: Optional[bytes] = None,
- tar_list: Optional[List[bytes]] = [], msl: Optional[int] = 0x06):
- super().__init__(decoded)
+ tar_list: Optional[List[bytes]] = [], msl: Optional[int] = 0x06, **kwargs):
+ super().__init__(decoded, **kwargs)
ADM1_ACCESS = h2b('02000100')
if decoded:
return
@@ -783,8 +794,8 @@
class ProfileElementUSIM(FsProfileElement):
type = 'usim'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -804,8 +815,8 @@
class ProfileElementOptUSIM(FsProfileElement):
type = 'opt-usim'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -814,8 +825,8 @@
class ProfileElementISIM(FsProfileElement):
type = 'isim'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -830,8 +841,8 @@
class ProfileElementOptISIM(FsProfileElement):
type = 'opt-isim'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -841,8 +852,8 @@
class ProfileElementAKA(ProfileElement):
type = 'akaParameter'

- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults for a MNO-SD
@@ -918,8 +929,20 @@
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)
+ iccid: Optional[Hexstr] = '0'*20, profile_type: Optional[str] = None,
+ **kwargs):
+ """You would usually initialize an instance either with a "decoded" argument (as read from
+ a DER-encoded SAIP file via asn1tools), or [some of] the othe arguments in case you're
+ constructing a Profile Header from scratch.
+
+ Args:
+ decoded: asn1tools-generated decoded structure for this PE
+ ver_major: Major SAIP version
+ ver_minor: Minor SAIP version
+ iccid: ICCID of the profile
+ profile_type: operational, testing or bootstrap
+ """
+ super().__init__(decoded, **kwargs)
if decoded:
return
# provide some reasonable defaults
@@ -935,8 +958,8 @@

class ProfileElementEnd(ProfileElement):
type = 'end'
- def __init__(self, decoded: Optional[dict] = None):
- super().__init__(decoded)
+ def __init__(self, decoded: Optional[dict] = None, **kwargs):
+ super().__init__(decoded, **kwargs)

def bertlv_first_segment(binary: bytes) -> Tuple[bytes, bytes]:
"""obtain the first segment of a binary concatenation of BER-TLV objects.

To view, visit change 37843. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ib2b7f6d7428d03e9a8c23af39a61f450096c12bc
Gerrit-Change-Number: 37843
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>