import gzip
import sys
from argparse import ArgumentParser
- from collections import OrderedDict
+ from typing import List, Tuple, Dict, TextIO
import re
import json
- from .__about__ import __version__
from .checks import add_kconfig_checks, add_cmdline_checks, normalize_cmdline_options, add_sysctl_checks
- from .engine import populate_with_data, perform_checks, override_expected_value
+ from .engine import StrOrNone, TupleOrNone, ChecklistObjType
+ from .engine import print_unknown_options, populate_with_data, perform_checks, override_expected_value
- def _open(file: str, *args, **kwargs):
- open_method = open
- if file.endswith('.gz'):
- open_method = gzip.open
+ # kernel-hardening-checker version
+ __version__ = '0.6.6'
- if file.endswith('.gz'):
- return gzip.open(file, 'rt', encoding='utf-8')
- return open(file, 'rt', encoding='utf-8')
+
+ def _open(file: str) -> TextIO:
- return open_method(file, *args, **kwargs)
+ try:
++ if file.endswith('.gz'):
++ return gzip.open(file, 'rt', encoding='utf-8')
++ return open(file, 'rt', encoding='utf-8')
+ except FileNotFoundError:
+ sys.exit(f'[!] ERROR: unable to open {file}, are you sure it exists?')
-
- def detect_arch(fname, archs):
- with _open(fname, 'rt', encoding='utf-8') as f:
+ def detect_arch(fname: str, archs: List[str]) -> Tuple[StrOrNone, str]:
+ with _open(fname) as f:
arch_pattern = re.compile(r"CONFIG_[a-zA-Z0-9_]+=y$")
arch = None
for line in f.readlines():