diff options
author | Harald Welte <laforge@osmocom.org> | 2023-12-28 15:06:11 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2023-12-29 18:51:25 +0100 |
commit | db1684df044c9d7ac2ae3802df8e6d7109000b27 (patch) | |
tree | 503c09d9f9f1c7f5ba00e2a6793459f5941f0723 | |
parent | ce01f48b0084e067abd7718e207a6f2b85a5471e (diff) |
sysmocom_sja2: Implement EF_CHV files using construct
this has the advantage of getting the encoder for free (so far we only
had the decoder). While at it, also add some tests data for the unit
tests.
Change-Id: Ifb8caf5cd96706d7fb6b452d6552b115c0828797
-rw-r--r-- | pySim/sysmocom_sja2.py | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/pySim/sysmocom_sja2.py b/pySim/sysmocom_sja2.py index a25bece..5bec446 100644 --- a/pySim/sysmocom_sja2.py +++ b/pySim/sysmocom_sja2.py @@ -46,27 +46,31 @@ mac_length = { class EF_PIN(TransparentEF): - def __init__(self, fid, name): + _test_de_encode = [ + ( 'f1030331323334ffffffff0a0a3132333435363738', + { 'state': { 'valid': True, 'change_able': True, 'unblock_able': True, 'disable_able': True, + 'not_initialized': False, 'disabled': True }, + 'attempts_remaining': 3, 'maximum_attempts': 3, 'pin': '31323334', + 'puk': { 'attempts_remaining': 10, 'maximum_attempts': 10, 'puk': '3132333435363738' } + } ), + ( 'f003039999999999999999', + { 'state': { 'valid': True, 'change_able': True, 'unblock_able': True, 'disable_able': True, + 'not_initialized': False, 'disabled': False }, + 'attempts_remaining': 3, 'maximum_attempts': 3, 'pin': '9999999999999999', + 'puk': None } ), + ] + def __init__(self, fid='6f01', name='EF.CHV1'): super().__init__(fid, name=name, desc='%s PIN file' % name) - - def _decode_bin(self, raw_bin_data): - u = unpack('!BBB8s', raw_bin_data[:11]) - res = {'enabled': (True, False)[u[0] & 0x01], - 'initialized': (True, False)[u[0] & 0x02], - 'disable_able': (False, True)[u[0] & 0x10], - 'unblock_able': (False, True)[u[0] & 0x20], - 'change_able': (False, True)[u[0] & 0x40], - 'valid': (False, True)[u[0] & 0x80], - 'attempts_remaining': u[1], - 'maximum_attempts': u[2], - 'pin': u[3].hex(), - } - if len(raw_bin_data) == 21: - u2 = unpack('!BB8s', raw_bin_data[11:10]) - res['attempts_remaining_puk'] = u2[0] - res['maximum_attempts_puk'] = u2[1] - res['puk'] = u2[2].hex() - return res + StateByte = FlagsEnum(Byte, disabled=1, not_initialized=2, disable_able=0x10, unblock_able=0x20, + change_able=0x40, valid=0x80) + PukStruct = Struct('attempts_remaining'/Int8ub, + 'maximum_attempts'/Int8ub, + 'puk'/HexAdapter(Rpad(Bytes(8)))) + self._construct = Struct('state'/StateByte, + 'attempts_remaining'/Int8ub, + 'maximum_attempts'/Int8ub, + 'pin'/HexAdapter(Rpad(Bytes(8))), + 'puk'/Optional(PukStruct)) class EF_MILENAGE_CFG(TransparentEF): |