From: Alexander Popov Date: Sat, 9 Mar 2024 18:53:47 +0000 (+0300) Subject: Implement the set_state() method of the check classes X-Git-Tag: v0.6.10~103 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=7de599403de2af9be38f8b50e0bccd32576c55a2;p=kconfig-hardened-check.git Implement the set_state() method of the check classes Refers to #88, #89, #97 --- diff --git a/kernel_hardening_checker/engine.py b/kernel_hardening_checker/engine.py index f52c446..8ba34ef 100644 --- a/kernel_hardening_checker/engine.py +++ b/kernel_hardening_checker/engine.py @@ -61,6 +61,12 @@ class OptCheck: def type(self): return None + def set_state(self, data): + if data: + assert(isinstance(data, str)), \ + f'invalid state "{data}" for "{self.name}" check' + self.state = data + def check(self): # handle the 'is present' check if self.expected == 'is present': @@ -130,7 +136,7 @@ class SysctlCheck(OptCheck): class VersionCheck: def __init__(self, ver_expected): assert(ver_expected and isinstance(ver_expected, tuple) and len(ver_expected) == 3), \ - f'invalid version "{ver_expected}" for VersionCheck' + f'invalid expected version "{ver_expected}" for VersionCheck' self.ver_expected = ver_expected self.ver = () self.result = None @@ -139,6 +145,11 @@ class VersionCheck: def type(self): return 'version' + def set_state(self, data): + assert(data and isinstance(data, tuple) and len(data) >= 3), \ + f'invalid version "{data}" for VersionCheck' + self.ver = data[:3] + def check(self): if self.ver[0] > self.ver_expected[0]: self.result = f'OK: version >= {self.ver_expected[0]}.{self.ver_expected[1]}' @@ -280,11 +291,11 @@ def populate_simple_opt_with_data(opt, data, data_type): return if data_type in ('kconfig', 'cmdline', 'sysctl'): - opt.state = data.get(opt.name, None) + opt.set_state(data.get(opt.name, None)) else: assert(data_type == 'version'), \ f'unexpected data type "{data_type}"' - opt.ver = data + opt.set_state(data) def populate_opt_with_data(opt, data, data_type):