aboutsummaryrefslogtreecommitdiffhomepage
path: root/sec_certs/sample
diff options
context:
space:
mode:
authorAdam Janovsky2022-02-11 15:39:53 +0100
committerAdam Janovsky2022-02-11 15:39:53 +0100
commit4da64a00bc1a2b7db82057cb9c4945ee2536cee2 (patch)
tree866408c248f2695ff2d779340aec1de9951866ad /sec_certs/sample
parentb2bd22877fe7917021a21818688280d6ed75b8e2 (diff)
downloadsec-certs-4da64a00bc1a2b7db82057cb9c4945ee2536cee2.tar.gz
sec-certs-4da64a00bc1a2b7db82057cb9c4945ee2536cee2.tar.zst
sec-certs-4da64a00bc1a2b7db82057cb9c4945ee2536cee2.zip
finish typing for auxilarry sample clases
Diffstat (limited to 'sec_certs/sample')
-rw-r--r--sec_certs/sample/cc_maintenance_update.py4
-rw-r--r--sec_certs/sample/cpe.py12
-rw-r--r--sec_certs/sample/cve.py17
-rw-r--r--sec_certs/sample/protection_profile.py10
4 files changed, 22 insertions, 21 deletions
diff --git a/sec_certs/sample/cc_maintenance_update.py b/sec_certs/sample/cc_maintenance_update.py
index fa4012e3..54c150f8 100644
--- a/sec_certs/sample/cc_maintenance_update.py
+++ b/sec_certs/sample/cc_maintenance_update.py
@@ -57,7 +57,7 @@ class CommonCriteriaMaintenanceUpdate(CommonCriteriaCert, ComplexSerializableTyp
return ["dgst"] + list(self.__class__.__init__.__code__.co_varnames)[1:]
@property
- def dgst(self):
+ def dgst(self) -> str:
return "cert_" + self.related_cert_digest + "_update_" + helpers.get_first_16_bytes_sha256(self.name)
@property
@@ -70,7 +70,7 @@ class CommonCriteriaMaintenanceUpdate(CommonCriteriaCert, ComplexSerializableTyp
return cls(*(tuple(dct.values()))) # TODO: Deserves some inheritance
@classmethod
- def get_updates_from_cc_cert(cls, cert: CommonCriteriaCert):
+ def get_updates_from_cc_cert(cls, cert: CommonCriteriaCert) -> List["CommonCriteriaMaintenanceUpdate"]:
if cert.maintenance_updates is None:
raise RuntimeError("Dataset was probably not built correctly - this should not be happening.")
diff --git a/sec_certs/sample/cpe.py b/sec_certs/sample/cpe.py
index 1abdc4e3..a5ce6921 100644
--- a/sec_certs/sample/cpe.py
+++ b/sec_certs/sample/cpe.py
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from functools import lru_cache
-from typing import ClassVar, Dict, List, Optional, Tuple
+from typing import Any, ClassVar, Dict, List, Optional, Tuple
from sec_certs.serialization.json import ComplexSerializableType
from sec_certs.serialization.pandas import PandasSerializableType
@@ -44,13 +44,13 @@ class CPE(PandasSerializableType, ComplexSerializableType):
self.start_version = start_version
self.end_version = end_version
- def __lt__(self, other: "CPE"):
+ def __lt__(self, other: "CPE") -> bool:
if self.title is None or other.title is None:
raise RuntimeError("Cannot compare CPEs because title is missing.")
return self.title < other.title
@classmethod
- def from_dict(cls, dct: Dict):
+ def from_dict(cls, dct: Dict[str, Any]) -> "CPE":
if isinstance(dct["start_version"], list):
dct["start_version"] = tuple(dct["start_version"])
if isinstance(dct["end_version"], list):
@@ -74,13 +74,13 @@ class CPE(PandasSerializableType, ComplexSerializableType):
return " ".join(self.uri.split(":")[11].split("_"))
@property
- def pandas_tuple(self):
+ def pandas_tuple(self) -> Tuple:
return self.uri, self.vendor, self.item_name, self.version, self.title
- def __hash__(self):
+ def __hash__(self) -> int:
return hash((self.uri, self.start_version, self.end_version))
- def __eq__(self, other):
+ def __eq__(self, other: object) -> bool:
return (
isinstance(other, self.__class__)
and self.uri == other.uri
diff --git a/sec_certs/sample/cve.py b/sec_certs/sample/cve.py
index 99c9b2af..6a0a3b39 100644
--- a/sec_certs/sample/cve.py
+++ b/sec_certs/sample/cve.py
@@ -1,7 +1,7 @@
import datetime
import itertools
from dataclasses import dataclass
-from typing import ClassVar, Dict, List, Optional, Tuple
+from typing import Any, ClassVar, Dict, List, Optional, Tuple
from dateutil.parser import isoparse
@@ -22,7 +22,7 @@ class CVE(PandasSerializableType, ComplexSerializableType):
__slots__ = ["base_score", "severity", "exploitability_score", "impact_score"]
@classmethod
- def from_nist_dict(cls, dct: Dict):
+ def from_nist_dict(cls, dct: Dict[str, Any]) -> "CVE.Impact":
"""
Will load Impact from dictionary defined at https://nvd.nist.gov/feeds/json/cve/1.1
"""
@@ -42,6 +42,7 @@ class CVE(PandasSerializableType, ComplexSerializableType):
dct["impact"]["baseMetricV2"]["exploitabilityScore"],
dct["impact"]["baseMetricV2"]["impactScore"],
)
+ raise ValueError("NIST Dict for CVE Impact badly formatted.")
cve_id: str
vulnerable_cpes: List[CPE]
@@ -67,15 +68,15 @@ class CVE(PandasSerializableType, ComplexSerializableType):
self.impact = impact
self.published_date = isoparse(published_date)
- def __hash__(self):
+ def __hash__(self) -> int:
return hash(self.cve_id)
- def __eq__(self, other):
+ def __eq__(self, other: object) -> bool:
if not isinstance(other, CVE):
return False
return self.cve_id == other.cve_id
- def __lt__(self, other):
+ def __lt__(self, other: object) -> bool:
if not isinstance(other, CVE):
raise ValueError(f"Cannot compare CVE with {type(other)} type.")
self_year = int(self.cve_id.split("-")[1])
@@ -97,16 +98,16 @@ class CVE(PandasSerializableType, ComplexSerializableType):
self.published_date,
)
- def to_dict(self):
+ def to_dict(self) -> Dict[str, Any]:
return {
"cve_id": self.cve_id,
"vulnerable_cpes": self.vulnerable_cpes,
"impact": self.impact,
- "published_date": self.published_date.isoformat(),
+ "published_date": self.published_date.isoformat() if self.published_date else None,
}
@staticmethod
- def _parse_nist_dict(lst: List, cpe_uris: List):
+ def _parse_nist_dict(lst: List, cpe_uris: List) -> None:
for x in lst:
if x["vulnerable"]:
cpe_uri = x["cpe23Uri"]
diff --git a/sec_certs/sample/protection_profile.py b/sec_certs/sample/protection_profile.py
index d8825ced..f97dc9fc 100644
--- a/sec_certs/sample/protection_profile.py
+++ b/sec_certs/sample/protection_profile.py
@@ -1,7 +1,7 @@
import copy
import logging
from dataclasses import dataclass
-from typing import Dict, FrozenSet, Optional
+from typing import Any, Dict, FrozenSet, Optional
import sec_certs.helpers as helpers
from sec_certs.serialization.json import ComplexSerializableType
@@ -24,22 +24,22 @@ class ProtectionProfile(ComplexSerializableType):
super().__setattr__("pp_link", helpers.sanitize_link(self.pp_link))
@classmethod
- def from_dict(cls, dct):
+ def from_dict(cls, dct: Dict[str, Any]) -> "ProtectionProfile":
new_dct = copy.deepcopy(dct)
new_dct["pp_ids"] = frozenset(new_dct["pp_ids"]) if new_dct["pp_ids"] else None
return cls(*tuple(new_dct.values()))
@classmethod
- def from_old_api_dict(cls, dct: Dict):
+ def from_old_api_dict(cls, dct: Dict[str, Any]) -> "ProtectionProfile":
pp_name = helpers.sanitize_string(dct["csv_scan"]["cc_pp_name"])
pp_link = helpers.sanitize_link(dct["csv_scan"]["link_pp_document"])
pp_ids = frozenset(dct["processed"]["cc_pp_csvid"]) if dct["processed"]["cc_pp_csvid"] else None
return cls(pp_name, pp_link, pp_ids)
- def __eq__(self, other):
+ def __eq__(self, other: object) -> bool:
if not isinstance(other, ProtectionProfile):
return False
return self.pp_name == other.pp_name and self.pp_link == other.pp_link
- def __lt__(self, other):
+ def __lt__(self, other: "ProtectionProfile") -> bool:
return self.pp_name < other.pp_name