mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-30 15:50:05 +03:00
personalization: indicate default ParamSource per ConfigurableParameter
Add default_source class members pointing to ParamSource classes to all ConfigurableParameter subclasses. This is useful to automatically set up a default ParamSource for a given ConfigurableParameter subclass, during user interaction to produce a batch personalization. For example, if the user selects a Pin1 parameter, a calling program can implicitly set this to a RandomDigitSource, which will magically make it work the way that most users need. BTW, default_source and default_value can be combined to configure a matching ParamSource instance: my_source = MyParam.default_source.from_str( MyParam.default_value ) Change-Id: Ie58d13bce3fa1aa2547cf3cee918c2f5b30a8b32
This commit is contained in:
@@ -143,6 +143,7 @@ class ConfigurableParameter:
|
|||||||
max_len = None
|
max_len = None
|
||||||
allow_len = None # a list of specific lengths
|
allow_len = None # a list of specific lengths
|
||||||
default_value = None
|
default_value = None
|
||||||
|
default_source = None # a param_source.ParamSource subclass
|
||||||
|
|
||||||
def __init__(self, input_value=None):
|
def __init__(self, input_value=None):
|
||||||
self.input_value = input_value # the raw input value as given by caller
|
self.input_value = input_value # the raw input value as given by caller
|
||||||
@@ -361,6 +362,7 @@ class BinaryParam(ConfigurableParameter):
|
|||||||
allow_types = (str, io.BytesIO, bytes, bytearray)
|
allow_types = (str, io.BytesIO, bytes, bytearray)
|
||||||
allow_chars = '0123456789abcdefABCDEF'
|
allow_chars = '0123456789abcdefABCDEF'
|
||||||
strip_chars = ' \t\r\n'
|
strip_chars = ' \t\r\n'
|
||||||
|
default_source = param_source.RandomHexDigitSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_val(cls, val):
|
def validate_val(cls, val):
|
||||||
@@ -388,6 +390,7 @@ class Iccid(DecimalParam):
|
|||||||
min_len = 18
|
min_len = 18
|
||||||
max_len = 20
|
max_len = 20
|
||||||
default_value = '0' * 18
|
default_value = '0' * 18
|
||||||
|
default_source = param_source.IncDigitSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_val(cls, val):
|
def validate_val(cls, val):
|
||||||
@@ -421,6 +424,7 @@ class Imsi(DecimalParam):
|
|||||||
min_len = 6
|
min_len = 6
|
||||||
max_len = 15
|
max_len = 15
|
||||||
default_value = '00101' + ('0' * 10)
|
default_value = '00101' + ('0' * 10)
|
||||||
|
default_source = param_source.IncDigitSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def apply_val(cls, pes: ProfileElementSequence, val):
|
def apply_val(cls, pes: ProfileElementSequence, val):
|
||||||
@@ -632,6 +636,7 @@ class Puk(DecimalHexParam):
|
|||||||
rpad = 16
|
rpad = 16
|
||||||
keyReference = None
|
keyReference = None
|
||||||
default_value = '0' * allow_len
|
default_value = '0' * allow_len
|
||||||
|
default_source = param_source.RandomDigitSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def apply_val(cls, pes: ProfileElementSequence, val):
|
def apply_val(cls, pes: ProfileElementSequence, val):
|
||||||
@@ -669,6 +674,7 @@ class Pin(DecimalHexParam):
|
|||||||
min_len = 4
|
min_len = 4
|
||||||
max_len = 8
|
max_len = 8
|
||||||
default_value = '0' * max_len
|
default_value = '0' * max_len
|
||||||
|
default_source = param_source.RandomDigitSource
|
||||||
keyReference = None
|
keyReference = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -786,6 +792,7 @@ class AlgorithmID(DecimalParam, AlgoConfig):
|
|||||||
algo_config_key = 'algorithmID'
|
algo_config_key = 'algorithmID'
|
||||||
allow_len = 1
|
allow_len = 1
|
||||||
default_value = 1 # Milenage
|
default_value = 1 # Milenage
|
||||||
|
default_source = param_source.ConstantSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_val(cls, val):
|
def validate_val(cls, val):
|
||||||
@@ -816,6 +823,7 @@ class MilenageRotationConstants(BinaryParam, AlgoConfig):
|
|||||||
algo_config_key = 'rotationConstants'
|
algo_config_key = 'rotationConstants'
|
||||||
allow_len = 5 # length in bytes (from BinaryParam)
|
allow_len = 5 # length in bytes (from BinaryParam)
|
||||||
default_value = '0a 0b 0c 0d 0e'
|
default_value = '0a 0b 0c 0d 0e'
|
||||||
|
default_source = param_source.ConstantSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_val(cls, val):
|
def validate_val(cls, val):
|
||||||
@@ -848,6 +856,7 @@ class TuakNumberOfKeccak(IntegerParam, AlgoConfig):
|
|||||||
min_val = 1
|
min_val = 1
|
||||||
max_val = 255
|
max_val = 255
|
||||||
default_value = '1'
|
default_value = '1'
|
||||||
|
default_source = param_source.ConstantSource
|
||||||
|
|
||||||
|
|
||||||
class BatchPersonalization:
|
class BatchPersonalization:
|
||||||
|
|||||||
Reference in New Issue
Block a user