neels has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/40825?usp=email )
Change subject: personalization: add int as input type for BinaryParameter
......................................................................
personalization: add int as input type for BinaryParameter
Change-Id: I31d8142cb0847a8b291f8dc614d57cb4734f0190
---
M pySim/esim/saip/personalization.py
M tests/unittests/test_configurable_parameters.py
2 files changed, 47 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/25/40825/1
diff --git a/pySim/esim/saip/personalization.py b/pySim/esim/saip/personalization.py
index 39f1cdf..216334d 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -356,13 +356,17 @@
class BinaryParam(ConfigurableParameter):
- allow_types = (str, io.BytesIO, bytes, bytearray)
+ allow_types = (str, io.BytesIO, bytes, bytearray, int)
allow_chars = '0123456789abcdefABCDEF'
strip_chars = ' \t\r\n'
@classmethod
def validate_val(cls, val):
# take care that min_len and max_len are applied to the binary length by
converting to bytes first
+ if isinstance(val, int):
+ min_len, _max_len = cls.get_len_range()
+ val = '%0*d' % (min_len, val)
+
if isinstance(val, str):
if cls.strip_chars is not None:
val = ''.join(c for c in val if c not in cls.strip_chars)
diff --git a/tests/unittests/test_configurable_parameters.py
b/tests/unittests/test_configurable_parameters.py
index c4e95ff..0237033 100755
--- a/tests/unittests/test_configurable_parameters.py
+++ b/tests/unittests/test_configurable_parameters.py
@@ -81,6 +81,10 @@
val='12345678',
expect_clean_val=b'12345678',
expect_val='12345678'),
+ Paramtest(param_cls=p13n.Puk1,
+ val=int(12345678),
+ expect_clean_val=b'12345678',
+ expect_val='12345678'),
Paramtest(param_cls=p13n.Puk2,
val='12345678',
@@ -99,6 +103,18 @@
val='12345678',
expect_clean_val=b'12345678',
expect_val='12345678'),
+ Paramtest(param_cls=p13n.Pin1,
+ val=int(1234),
+ expect_clean_val=b'1234\xff\xff\xff\xff',
+ expect_val='1234'),
+ Paramtest(param_cls=p13n.Pin1,
+ val=int(123456),
+ expect_clean_val=b'123456\xff\xff',
+ expect_val='123456'),
+ Paramtest(param_cls=p13n.Pin1,
+ val=int(12345678),
+ expect_clean_val=b'12345678',
+ expect_val='12345678'),
Paramtest(param_cls=p13n.Adm1,
val='1234',
@@ -112,6 +128,10 @@
val='12345678',
expect_clean_val=b'12345678',
expect_val='12345678'),
+ Paramtest(param_cls=p13n.Adm1,
+ val=int(123456),
+ expect_clean_val=b'123456\xff\xff',
+ expect_val='123456'),
Paramtest(param_cls=p13n.AlgorithmID,
val='Milenage',
@@ -126,6 +146,19 @@
expect_clean_val=3,
expect_val='usim-test'),
+ Paramtest(param_cls=p13n.AlgorithmID,
+ val=1,
+ expect_clean_val=1,
+ expect_val='Milenage'),
+ Paramtest(param_cls=p13n.AlgorithmID,
+ val=2,
+ expect_clean_val=2,
+ expect_val='TUAK'),
+ Paramtest(param_cls=p13n.AlgorithmID,
+ val=3,
+ expect_clean_val=3,
+ expect_val='usim-test'),
+
Paramtest(param_cls=p13n.K,
val='01020304050607080910111213141516',
expect_clean_val=b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16',
@@ -142,6 +175,10 @@
val=io.BytesIO(b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16'),
expect_clean_val=b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16',
expect_val='01020304050607080910111213141516'),
+ Paramtest(param_cls=p13n.K,
+ val=int(11020304050607080910111213141516),
+
expect_clean_val=b'\x11\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16',
+ expect_val='11020304050607080910111213141516'),
Paramtest(param_cls=p13n.Opc,
val='01020304050607080910111213141516',
@@ -233,6 +270,11 @@
expect_clean_val=b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16',
expect_val='01020304050607080910111213141516',
),
+ Paramtest(param_cls=sdkey_cls,
+ val=11020304050607080910111213141516,
+
expect_clean_val=b'\x11\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16',
+ expect_val='11020304050607080910111213141516',
+ ),
])
for upp_fname in upp_fnames:
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/40825?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: I31d8142cb0847a8b291f8dc614d57cb4734f0190
Gerrit-Change-Number: 40825
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>