diff options
| author | GeogeFI | 2022-12-16 17:24:38 +0100 |
|---|---|---|
| committer | GeogeFI | 2022-12-16 17:24:38 +0100 |
| commit | d9bf915d0ae1a13d6746b0e49c02e5b44ff5c56d (patch) | |
| tree | 0e6b8a3d29e32d326d1e317b0295adb490d6f0e5 | |
| parent | 929ca521e62aef041302c0b5c4260bf4c58736f7 (diff) | |
| download | sec-certs-d9bf915d0ae1a13d6746b0e49c02e5b44ff5c56d.tar.gz sec-certs-d9bf915d0ae1a13d6746b0e49c02e5b44ff5c56d.tar.zst sec-certs-d9bf915d0ae1a13d6746b0e49c02e5b44ff5c56d.zip | |
docs: Added documentation to the major methods
| -rw-r--r-- | src/sec_certs/dataset/cve.py | 5 | ||||
| -rw-r--r-- | src/sec_certs/sample/cpe.py | 4 | ||||
| -rw-r--r-- | src/sec_certs/sample/cve.py | 10 | ||||
| -rw-r--r-- | tests/test_cve.py | 1 |
4 files changed, 20 insertions, 0 deletions
diff --git a/src/sec_certs/dataset/cve.py b/src/sec_certs/dataset/cve.py index 954d950e..c370f3ce 100644 --- a/src/sec_certs/dataset/cve.py +++ b/src/sec_certs/dataset/cve.py @@ -166,6 +166,11 @@ class CVEDataset(JSONPathDataset, ComplexSerializableType): } def get_cves_from_matched_cpes(self, cpe_matches: set[str]) -> set[str]: + """ + Method returns the set of CVEs which are matched to the set of CPEs. + First are matched the classic CPEs to CVEs with lookup dict and then are matched the + 'AND' type CPEs containing platform. + """ cves = self._get_cves_from_exactly_matched_cpes(cpe_matches) cves_matched_by_configurations = self._get_cves_from_cpe_configurations(cpe_matches) cves.update(cves_matched_by_configurations) diff --git a/src/sec_certs/sample/cpe.py b/src/sec_certs/sample/cpe.py index 273b612d..29e078b6 100644 --- a/src/sec_certs/sample/cpe.py +++ b/src/sec_certs/sample/cpe.py @@ -23,6 +23,10 @@ class CPEConfiguration(ComplexSerializableType): return isinstance(other, self.__class__) and self.platform == other.platform and self.cpes == other.cpes def match(self, set_of_cpes: set[str]) -> bool: + """ + For a given set of CPEs method returns boolean if the CPE configuration is + matched or not. + """ return self.platform in set_of_cpes and any([cpe for cpe in set_of_cpes]) diff --git a/src/sec_certs/sample/cve.py b/src/sec_certs/sample/cve.py index 80e786cd..ab18b310 100644 --- a/src/sec_certs/sample/cve.py +++ b/src/sec_certs/sample/cve.py @@ -118,6 +118,7 @@ class CVE(PandasSerializableType, ComplexSerializableType): return { "cve_id": self.cve_id, "vulnerable_cpes": self.vulnerable_cpes, + "vulnerable_cpe_configurations": self.vulnerable_cpe_configurations, "impact": self.impact, "published_date": self.published_date.isoformat() if self.published_date else None, "cwe_ids": self.cwe_ids, @@ -151,6 +152,11 @@ class CVE(PandasSerializableType, ComplexSerializableType): @staticmethod def _parse_nist_dict(cpe_list: list[dict[str, Any]], parse_only_vulnerable_cpes: bool) -> list[CPE]: + """ + Method parses list of CPE dicts to the list of CPE objects. + The <parse_only_vulnerable_cpes> parameter specifies if we want to + parse only vulnerable CPEs or not. + """ cpe_dicts_to_be_parsed = cpe_list if parse_only_vulnerable_cpes: @@ -185,6 +191,10 @@ class CVE(PandasSerializableType, ComplexSerializableType): def get_vulnerable_cpes_and_cpe_configurations( node: dict, cpes: list[CPE], cpe_configurations: list[CPEConfiguration] ) -> tuple[list[CPE], list[CPEConfiguration]]: + """ + Method traverses node of CPE tree and returns the list of CPEs and CPE configuratios, + which depends on if the parent node is OR/AND type. + """ if node["operator"] == "AND": cpe_configurations.extend(get_cpe_configurations_from_and_cpe_dict(node["children"])) return cpes, cpe_configurations diff --git a/tests/test_cve.py b/tests/test_cve.py index 02c80474..a9c35d4a 100644 --- a/tests/test_cve.py +++ b/tests/test_cve.py @@ -46,6 +46,7 @@ def cve_dict() -> dict[str, Any]: "end_version": None, } ], + "vulnerable_cpe_configurations": [], "impact": { "_type": "Impact", "base_score": 5, |
