MCPcopy
hub / github.com/jtesta/ssh-audit / Software

Class Software

src/ssh_audit/software.py:34–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class Software:
35 def __init__(self, vendor: Optional[str], product: str, version: str, patch: Optional[str], os_version: Optional[str]) -> None:
36 self.__vendor = vendor
37 self.__product = product
38 self.__version = version
39 self.__patch = patch
40 self.__os = os_version
41
42 @property
43 def vendor(self) -> Optional[str]:
44 return self.__vendor
45
46 @property
47 def product(self) -> str:
48 return self.__product
49
50 @property
51 def version(self) -> str:
52 return self.__version
53
54 @property
55 def patch(self) -> Optional[str]:
56 return self.__patch
57
58 @property
59 def os(self) -> Optional[str]:
60 return self.__os
61
62 def compare_version(self, other: Union[None, 'Software', str]) -> int:
63 # pylint: disable=too-many-branches,too-many-return-statements
64 if other is None:
65 return 1
66 if isinstance(other, Software):
67 other = '{}{}'.format(other.version, other.patch or '')
68 else:
69 other = str(other)
70 mx = re.match(r'^([\d\.]+\d+)(.*)$', other)
71 if mx is not None:
72 oversion, opatch = mx.group(1), mx.group(2).strip()
73 else:
74 oversion, opatch = other, ''
75 if self.version < oversion:
76 return -1
77 elif self.version > oversion:
78 return 1
79 spatch = self.patch or ''
80 if self.product == Product.DropbearSSH:
81 if not re.match(r'^test\d.*$', opatch):
82 opatch = 'z{}'.format(opatch)
83 if not re.match(r'^test\d.*$', spatch):
84 spatch = 'z{}'.format(spatch)
85 elif self.product == Product.OpenSSH:
86 mx1 = re.match(r'^p(\d).*', opatch)
87 mx2 = re.match(r'^p(\d).*', spatch)
88 if not (bool(mx1) and bool(mx2)):
89 if mx1 is not None:
90 opatch = mx1.group(1)
91 if mx2 is not None:

Callers 1

output_compatibilityFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected