mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 16:28:33 +03:00
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
This commit is contained in:
@@ -225,7 +225,19 @@ class ProfileElement:
|
|||||||
'securityDomain': 'sd-Header',
|
'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 which we're part of
|
||||||
|
"""
|
||||||
|
self.pe_sequence = pe_sequence
|
||||||
if decoded:
|
if decoded:
|
||||||
self.decoded = decoded
|
self.decoded = decoded
|
||||||
else:
|
else:
|
||||||
@@ -301,14 +313,20 @@ class ProfileElement:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_der(cls, der: bytes) -> 'ProfileElement':
|
def from_der(cls, der: bytes,
|
||||||
"""Construct an instance from given raw, DER encoded 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_type, decoded = asn1.decode('ProfileElement', der)
|
||||||
pe_cls = cls.class_for_petype(pe_type)
|
pe_cls = cls.class_for_petype(pe_type)
|
||||||
if pe_cls:
|
if pe_cls:
|
||||||
inst = pe_cls(decoded)
|
inst = pe_cls(decoded, pe_sequence=pe_sequence)
|
||||||
else:
|
else:
|
||||||
inst = ProfileElement(decoded)
|
inst = ProfileElement(decoded, pe_sequence=pe_sequence)
|
||||||
inst.type = pe_type
|
inst.type = pe_type
|
||||||
# run any post-decoder a derived class may have
|
# run any post-decoder a derived class may have
|
||||||
if hasattr(inst, '_post_decode'):
|
if hasattr(inst, '_post_decode'):
|
||||||
@@ -984,7 +1002,7 @@ class ProfileElementSequence:
|
|||||||
remainder = der
|
remainder = der
|
||||||
while len(remainder):
|
while len(remainder):
|
||||||
first_tlv, remainder = bertlv_first_segment(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()
|
self._process_pelist()
|
||||||
|
|
||||||
def _process_pelist(self) -> None:
|
def _process_pelist(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user