personalization: add int as input type for BinaryParameter

Change-Id: I31d8142cb0847a8b291f8dc614d57cb4734f0190
This commit is contained in:
Neels Hofmeyr
2025-08-04 18:50:44 +02:00
parent 913e8d12d4
commit 9e33ae0486
3 changed files with 186 additions and 1 deletions

View File

@@ -369,7 +369,7 @@ class IntegerParam(ConfigurableParameter):
yield valdict
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'
default_source = param_source.RandomHexDigitSource
@@ -377,6 +377,10 @@ class BinaryParam(ConfigurableParameter):
@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)