neels has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/42260?usp=email )
Change subject: ConfigurableParameter: safer val length check
......................................................................
ConfigurableParameter: safer val length check
Change-Id: Ibe91722ed1477b00d20ef5e4e7abd9068ff2f3e4
---
M pySim/esim/saip/personalization.py
1 file changed, 12 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/60/42260/1
diff --git a/pySim/esim/saip/personalization.py
b/pySim/esim/saip/personalization.py
index b28d88e..7d24453 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -191,19 +191,25 @@
elif isinstance(val, io.BytesIO):
val = val.getvalue()
+ if hasattr(val, '__len__'):
+ val_len = len(val)
+ else:
+ # e.g. int length
+ val_len = len(str(val))
+
if cls.allow_len is not None:
l = cls.allow_len
# cls.allow_len could be one int, or a tuple of ints. Wrap a
single int also in a tuple.
if not isinstance(l, (tuple, list)):
l = (l,)
- if len(val) not in l:
- raise ValueError(f'length must be one of {cls.allow_len}, not
{len(val)}: {val!r}')
+ if val_len not in l:
+ raise ValueError(f'length must be one of {cls.allow_len}, not
{val_len}: {val!r}')
if cls.min_len is not None:
- if len(val) < cls.min_len:
- raise ValueError(f'length must be at least {cls.min_len}, not
{len(val)}: {val!r}')
+ if val_len < cls.min_len:
+ raise ValueError(f'length must be at least {cls.min_len}, not
{val_len}: {val!r}')
if cls.max_len is not None:
- if len(val) > cls.max_len:
- raise ValueError(f'length must be at most {cls.max_len}, not
{len(val)}: {val!r}')
+ if val_len > cls.max_len:
+ raise ValueError(f'length must be at most {cls.max_len}, not
{val_len}: {val!r}')
return val
@classmethod
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42260?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: Ibe91722ed1477b00d20ef5e4e7abd9068ff2f3e4
Gerrit-Change-Number: 42260
Gerrit-PatchSet: 1
Gerrit-Owner: neels <[email protected]>