|
@@ -243,14 +243,49 @@ class BaseAttack(metaclass=ABCMeta):
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def _is_filepath(val: str):
|
|
def _is_filepath(val: str):
|
|
- '''
|
|
|
|
|
|
+ """
|
|
Verifies that the given string points to an existing file
|
|
Verifies that the given string points to an existing file
|
|
|
|
|
|
:param filepath: The filepath as string
|
|
:param filepath: The filepath as string
|
|
:return: True if the file at the given location exists, otherwise False
|
|
:return: True if the file at the given location exists, otherwise False
|
|
- '''
|
|
|
|
|
|
+ """
|
|
return os.path.isfile(val)
|
|
return os.path.isfile(val)
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _is_comm_type(val: str):
|
|
|
|
+ """
|
|
|
|
+ Verifies that the given string is a valid communications type
|
|
|
|
+
|
|
|
|
+ :param comm_type: the type of communication as a string
|
|
|
|
+ :return: True if the given type is a valid communications type, otherwise False
|
|
|
|
+ """
|
|
|
|
+ comm_types = {"local", "external", "mixed"}
|
|
|
|
+ return val in comm_types
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _is_percentage(val: float):
|
|
|
|
+ """
|
|
|
|
+ Verifies that the given float value is a valid percentage, i.e. between 0 and 1
|
|
|
|
+
|
|
|
|
+ :param percentage: the float to test for validity
|
|
|
|
+ :return: True if the given type is a valid percentage, otherwise False
|
|
|
|
+ """
|
|
|
|
+ if val >= 0 and val <= 1:
|
|
|
|
+ return True
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _is_padding(val: int):
|
|
|
|
+ """
|
|
|
|
+ Verifies that the given int is a valid padding size, i.e. between 0 and 100
|
|
|
|
+
|
|
|
|
+ :param padding: the padding to test for its size
|
|
|
|
+ :return: True if the given type is valid padding, False otherwise
|
|
|
|
+ """
|
|
|
|
+ if val >= 0 and val <= 100:
|
|
|
|
+ return True
|
|
|
|
+ return False
|
|
|
|
+
|
|
#########################################
|
|
#########################################
|
|
# HELPER METHODS
|
|
# HELPER METHODS
|
|
#########################################
|
|
#########################################
|
|
@@ -332,6 +367,23 @@ class BaseAttack(metaclass=ABCMeta):
|
|
is_valid = self._is_domain(value)
|
|
is_valid = self._is_domain(value)
|
|
elif param_type == ParameterTypes.TYPE_FILEPATH:
|
|
elif param_type == ParameterTypes.TYPE_FILEPATH:
|
|
is_valid = self._is_filepath(value)
|
|
is_valid = self._is_filepath(value)
|
|
|
|
+ elif param_type == ParameterTypes.TYPE_COMM_TYPE:
|
|
|
|
+ is_valid = self._is_comm_type(value)
|
|
|
|
+ elif param_type == ParameterTypes.TYPE_PERCENTAGE:
|
|
|
|
+ is_valid, value = self._is_float(value)
|
|
|
|
+ if is_valid and (param_name in {Parameter.IP_REUSE_TOTAL, Parameter.IP_REUSE_LOCAL, Parameter.IP_REUSE_EXTERNAL}):
|
|
|
|
+ is_valid = self._is_percentage(value)
|
|
|
|
+ else:
|
|
|
|
+ is_valid = False
|
|
|
|
+ elif param_type == ParameterTypes.TYPE_PADDING:
|
|
|
|
+ if isinstance(value, int):
|
|
|
|
+ is_valid = True
|
|
|
|
+ elif isinstance(value, str) and value.isdigit():
|
|
|
|
+ is_valid = True
|
|
|
|
+ value = int(value)
|
|
|
|
+
|
|
|
|
+ if is_valid:
|
|
|
|
+ is_valid = self._is_padding(value)
|
|
|
|
|
|
# add value iff validation was successful
|
|
# add value iff validation was successful
|
|
if is_valid:
|
|
if is_valid:
|