neels has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/39747?usp=email )
Change subject: [7/7] personalization: refactor SdKey
......................................................................
[7/7] personalization: refactor SdKey
Refactor SdKey (and subclasses) to the new ConfigurableParameter
implementation style, keeping the same implementation.
But duly note that this implementation does not work!
It correctly patches pe.decoded[], but that gets overridden by
ProfileElementSD._pre_encode().
For a fix, see I07dfc378705eba1318e9e8652796cbde106c6a52.
Change-Id: I427ea851bfa28b2b045e70a19a9e35d361f0d393
---
M pySim/esim/saip/personalization.py
1 file changed, 13 insertions(+), 20 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/47/39747/1
diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py
index c591c7d..6567520 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -196,44 +196,37 @@
val = super().validate_val(val)
return bytes(val)
-class SdKey(ConfigurableParameter):
+class SdKey(BinaryParam):
"""Configurable Security Domain (SD) Key. Value is presented as
bytes."""
- # these will be set by derived classes
+ # these will be set by subclasses
key_type = None
key_id = None
kvn = None
key_usage_qual = None
- permitted_len = None
- def validate(self):
- if not isinstance(self.input_value, (io.BytesIO, bytes, bytearray)):
- raise ValueError('Value must be of bytes-like type')
- if self.permitted_len:
- if len(self.input_value) not in self.permitted_len:
- raise ValueError('Value length must be %s' % self.permitted_len)
- self.value = self.input_value
-
- def _apply_sd(self, pe: ProfileElement):
+ @classmethod
+ def _apply_sd(cls, pe: ProfileElement, value):
assert pe.type == 'securityDomain'
for key in pe.decoded['keyList']:
- if key['keyIdentifier'][0] == self.key_id and
key['keyVersionNumber'][0] == self.kvn:
+ if key['keyIdentifier'][0] == cls.key_id and
key['keyVersionNumber'][0] == cls.kvn:
assert len(key['keyComponents']) == 1
- key['keyComponents'][0]['keyData'] = self.value
+ key['keyComponents'][0]['keyData'] = value
return
# Could not find matching key to patch, create a new one
key = {
- 'keyUsageQualifier': bytes([self.key_usage_qual]),
- 'keyIdentifier': bytes([self.key_id]),
- 'keyVersionNumber': bytes([self.kvn]),
+ 'keyUsageQualifier': bytes([cls.key_usage_qual]),
+ 'keyIdentifier': bytes([cls.key_id]),
+ 'keyVersionNumber': bytes([cls.kvn]),
'keyComponents': [
- { 'keyType': bytes([self.key_type]), 'keyData':
self.value },
+ { 'keyType': bytes([cls.key_type]), 'keyData': value },
]
}
pe.decoded['keyList'].append(key)
- def apply(self, pes: ProfileElementSequence):
+ @classmethod
+ def apply_val(cls, pes: ProfileElementSequence, value):
for pe in pes.get_pes_for_type('securityDomain'):
- self._apply_sd(pe)
+ cls._apply_sd(pe, value)
class SdKeyScp80_01(SdKey):
kvn = 0x01
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/39747?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: I427ea851bfa28b2b045e70a19a9e35d361f0d393
Gerrit-Change-Number: 39747
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>