laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/37842?usp=email )
Change subject: pySim.esim.saip: Back-reference from ProfileElement to
ProfileElementSequence
......................................................................
pySim.esim.saip: Back-reference from ProfileElement to ProfileElementSequence
Store a back-reference to the PE-Sequence in the PE object; this is
neccessary for some upcoming patches, e.g. to determine the position in
the sequence, access the global filesystem hierarchy, etc.
Change-Id: I24b692e47e4dd0afb5a17b04d5e0251dded3d611
---
M pySim/esim/saip/__init__.py
1 file changed, 24 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/42/37842/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index fb2097a..65396b1 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -225,7 +225,19 @@
'securityDomain': 'sd-Header',
}
- def __init__(self, decoded = None, mandated: bool = True):
+ def __init__(self, decoded = None, mandated: bool = True,
+ pe_sequence: Optional['ProfileElementSequence'] = None):
+ """
+ Instantiate a new ProfileElement. This is usually either called with
the 'decoded' argument after
+ reading a SAIP-DER-encoded PE. Alternatively, when constructing a PE
from scratch, decoded is None,
+ and a minimal PE-Header is generated.
+
+ Args:
+ decoded: asn1tools-generated decoded structure for this PE
+ mandated: Whether or not the PE-Header should contain the mandated
attribute
+ pe_sequence: back-reference to the PE-Sequence of whcih we're part
of
+ """
+ self.pe_sequence = pe_sequence
if decoded:
self.decoded = decoded
else:
@@ -301,14 +313,20 @@
return None
@classmethod
- def from_der(cls, der: bytes) -> 'ProfileElement':
- """Construct an instance from given raw, DER encoded bytes."""
+ def from_der(cls, der: bytes,
+ pe_sequence: Optional['ProfileElementSequence'] = None) ->
'ProfileElement':
+ """Construct an instance from given raw, DER encoded bytes.
+
+ Args:
+ der: raw, DER-encoded bytes of a single PE
+ pe_sequence: back-reference to the PE-Sequence of which this PE is
part of
+ """
pe_type, decoded = asn1.decode('ProfileElement', der)
pe_cls = cls.class_for_petype(pe_type)
if pe_cls:
- inst = pe_cls(decoded)
+ inst = pe_cls(decoded, pe_sequence=pe_sequence)
else:
- inst = ProfileElement(decoded)
+ inst = ProfileElement(decoded, pe_sequence=pe_sequence)
inst.type = pe_type
# run any post-decoder a derived class may have
if hasattr(inst, '_post_decode'):
@@ -961,7 +979,7 @@
remainder = der
while len(remainder):
first_tlv, remainder = bertlv_first_segment(remainder)
- self.pe_list.append(ProfileElement.from_der(first_tlv))
+ self.pe_list.append(ProfileElement.from_der(first_tlv,
pe_sequence=self))
self._process_pelist()
def _process_pelist(self) -> None:
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37842?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I24b692e47e4dd0afb5a17b04d5e0251dded3d611
Gerrit-Change-Number: 37842
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>