laforge has uploaded this change for review.

View Change

pySim.esim.saip: Refactor from_der() method to have class_for_petype()

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

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/37659/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 4b8ad76..9185e36 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -274,26 +274,48 @@
return self.decoded.get('templateID', None)

@classmethod
- def from_der(cls, der: bytes) -> 'ProfileElement':
+ def class_for_petype(cls, pe_type: str) -> Optional['ProfileElement']:
+ """Return the subclass implementing the given pe-type string."""
class4petype = {
- 'securityDomain': ProfileElementSD,
- 'mf': ProfileElementMF,
- 'pukCodes': ProfileElementPuk,
+ # use same order as ASN.1 source definition of "ProfileElement ::= CHOICE {"
+ 'header': ProfileElementHeader,
+ 'genericFileManagement': ProfileElementGFM,
'pinCodes': ProfileElementPin,
+ 'pukCodes': ProfileElementPuk,
+ 'akaParameter': ProfileElementAKA,
+ # TODO: cdmaParameter
+ 'securityDomain': ProfileElementSD,
+ # TODO: rfm
+ # TODO: application
+ # TODO: nonStandard
+ 'end': ProfileElementEnd,
+ 'mf': ProfileElementMF,
+ # TODO: cd
'telecom': ProfileElementTelecom,
'usim': ProfileElementUSIM,
'opt-usim': ProfileElementOptUSIM,
'isim': ProfileElementISIM,
'opt-isim': ProfileElementOptISIM,
- 'akaParameter': ProfileElementAKA,
- 'header': ProfileElementHeader,
- 'genericFileManagement': ProfileElementGFM,
- 'end': ProfileElementEnd,
+ # TODO: phonebook
+ # TODO: gsm-access
+ # TODO: csim
+ # TODO: opt-csim
+ # TODO: eap
+ # TODO: df-5gs
+ # TODO: df-saip
}
+ if pe_type in class4petype:
+ return class4petype[pe_type]
+ else:
+ return None
+
+ @classmethod
+ def from_der(cls, der: bytes) -> 'ProfileElement':
"""Construct an instance from given raw, DER encoded bytes."""
pe_type, decoded = asn1.decode('ProfileElement', der)
- if pe_type in class4petype:
- inst = class4petype[pe_type](decoded)
+ pe_cls = cls.class_for_petype(pe_type)
+ if pe_cls:
+ inst = pe_cls(decoded)
else:
inst = ProfileElement(decoded)
inst.type = pe_type

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

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