laforge has submitted this change. (
https://gerrit.osmocom.org/c/pysim/+/40827?usp=email )
(
9 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted
one.
)Change subject: param_source: allow plugging a random implementation (for
testing)
......................................................................
param_source: allow plugging a random implementation (for testing)
Change-Id: Idce2b18af70c17844d6f09f7704efc869456ac39
Jenkins: skip-card-test
---
M pySim/esim/saip/param_source.py
1 file changed, 7 insertions(+), 4 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/esim/saip/param_source.py b/pySim/esim/saip/param_source.py
index 2083f98..04a44fed 100644
--- a/pySim/esim/saip/param_source.py
+++ b/pySim/esim/saip/param_source.py
@@ -123,15 +123,18 @@
def val_to_digit(self, val:int):
return "%0*d" % (self.num_digits, val) # pylint:
disable=consider-using-f-string
-class RandomDigitSource(DecimalRangeSource):
+class RandomSourceMixin:
+ random_impl = random # TODO secure random source?
+
+class RandomDigitSource(DecimalRangeSource, RandomSourceMixin):
"""return a different sequence of random decimal digits each"""
name = "random decimal digits"
def get_next(self, csv_row:dict=None):
- val = random.randint(self.first_value, self.last_value) # TODO secure
random source?
+ val = self.random_impl.randint(self.first_value, self.last_value)
return self.val_to_digit(val)
-class RandomHexDigitSource(InputExpandingParamSource):
+class RandomHexDigitSource(InputExpandingParamSource, RandomSourceMixin):
"""return a different sequence of random hexadecimal digits each"""
name = "random hexadecimal digits"
numeric_base = 16
@@ -149,7 +152,7 @@
self.num_digits = num_digits
def get_next(self, csv_row:dict=None):
- val = random.randbytes(self.num_digits // 2) # TODO secure random
source?
+ val = self.random_impl.randbytes(self.num_digits // 2)
return b2h(val)
class IncDigitSource(DecimalRangeSource):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/40827?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idce2b18af70c17844d6f09f7704efc869456ac39
Gerrit-Change-Number: 40827
Gerrit-PatchSet: 10
Gerrit-Owner: neels <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>