2424
2525"""
2626This set of classes represents the data that is possible under the CycloneDX extension
27- schema for Vulnerabilties (version 1.0).
27+ schema for Vulnerabilities (version 1.0).
2828
29- See: https://github.com/CycloneDX/specification/blob/master/schema/ext/vulnerability-1.0.xsd
29+ .. note::
30+ See the CycloneDX Schema extension definition https://cyclonedx.org/ext/vulnerability/.
3031"""
3132
3233
3334class VulnerabilitySourceType (Enum ):
3435 """
35- Represents <xs:simpleType name="scoreSourceType">
36+ Enum object that defines the permissible source types for a Vulnerability.
37+
38+ .. note::
39+ See `scoreSourceType` in https://github.com/CycloneDX/specification/blob/master/schema/ext/vulnerability-1.0.xsd
3640 """
3741 CVSS_V2 = 'CVSSv2'
3842 CVSS_V3 = 'CVSSv3'
@@ -42,6 +46,17 @@ class VulnerabilitySourceType(Enum):
4246
4347 @staticmethod
4448 def get_from_vector (vector : str ):
49+ """
50+ Attempt to derive the correct SourceType from an attack vector.
51+
52+ For example, often attack vector strings are prefixed with the scheme in question - such
53+ that __CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:C/C:L/I:N/A:N__ would be the vector
54+ __AV:L/AC:L/PR:N/UI:R/S:C/C:L/I:N/A:N__ under the __CVSS 3__ scheme.
55+
56+ Returns:
57+ Always returns an instance of `VulnerabilitySourceType`. `VulnerabilitySourceType.OTHER` is returned if the
58+ scheme is not obvious or known to us.
59+ """
4560 if vector .startswith ('CVSS:3.' ):
4661 return VulnerabilitySourceType .CVSS_V3
4762 elif vector .startswith ('CVSS:2.' ):
@@ -53,12 +68,13 @@ def get_from_vector(vector: str):
5368
5469 def get_localised_vector (self , vector : str ) -> str :
5570 """
56- This method will remove any Source Scheme type from the supplied vector.
71+ This method will remove any Source Scheme type from the supplied vector, returning just the vector .
5772
58- For example if VulnerabilitySourceType.OWASP
73+ .. Note::
74+ Currently supports CVSS 3.x, CVSS 2.x and OWASP schemes.
5975
60- :param vector :
61- :return:
76+ Returns :
77+ The vector without any scheme prefix as a `str`.
6278 """
6379 if self == VulnerabilitySourceType .CVSS_V3 and vector .startswith ('CVSS:3.' ):
6480 return re .sub ('^CVSS:3\\ .\\ d/?' , '' , vector )
@@ -74,7 +90,10 @@ def get_localised_vector(self, vector: str) -> str:
7490
7591class VulnerabilitySeverity (Enum ):
7692 """
77- Represents <xs:simpleType name="severityType">
93+ Enum object that defines the permissible severities for a Vulnerability.
94+
95+ .. note::
96+ See `severityType` in https://github.com/CycloneDX/specification/blob/master/schema/ext/vulnerability-1.0.xsd
7897 """
7998 NONE = 'None'
8099 LOW = 'Low'
@@ -85,6 +104,15 @@ class VulnerabilitySeverity(Enum):
85104
86105 @staticmethod
87106 def get_from_cvss_scores (scores : tuple = None ):
107+ """
108+ Derives the Severity of a Vulnerability from it's declared CVSS scores.
109+
110+ Args:
111+ scores: A `tuple` of CVSS scores. CVSS scoring system allows for up to three separate scores.
112+
113+ Returns:
114+ Always returns an instance of `VulnerabilitySeverity`.
115+ """
88116 if type (scores ) is float :
89117 scores = (scores ,)
90118
@@ -107,7 +135,10 @@ def get_from_cvss_scores(scores: tuple = None):
107135
108136class VulnerabilityRating :
109137 """
110- Represents <xs:complexType name="scoreType">
138+ Class that models the `scoreType` complex element in the Vulnerability extension schema.
139+
140+ .. note::
141+ See `scoreType` in https://github.com/CycloneDX/specification/blob/master/schema/ext/vulnerability-1.0.xsd
111142 """
112143 _score_base : float
113144 _score_impact : float
@@ -130,18 +161,48 @@ def __init__(self, score_base: float = None, score_impact: float = None, score_e
130161 self ._vector = vector
131162
132163 def get_base_score (self ) -> float :
164+ """
165+ Get the base score of this VulnerabilityRating.
166+
167+ Returns:
168+ Declared base score of this VulnerabilityRating as `float`.
169+ """
133170 return self ._score_base
134171
135172 def get_impact_score (self ) -> float :
173+ """
174+ Get the impact score of this VulnerabilityRating.
175+
176+ Returns:
177+ Declared impact score of this VulnerabilityRating as `float`.
178+ """
136179 return self ._score_impact
137180
138181 def get_exploitability_score (self ) -> float :
182+ """
183+ Get the exploitability score of this VulnerabilityRating.
184+
185+ Returns:
186+ Declared exploitability score of this VulnerabilityRating as `float`.
187+ """
139188 return self ._score_exploitability
140189
141190 def get_severity (self ) -> Union [VulnerabilitySeverity , None ]:
191+ """
192+ Get the severity score of this VulnerabilityRating.
193+
194+ Returns:
195+ Declared severity of this VulnerabilityRating as `VulnerabilitySeverity` or `None`.
196+ """
142197 return self ._severity
143198
144199 def get_method (self ) -> Union [VulnerabilitySourceType , None ]:
200+ """
201+ Get the source method of this VulnerabilitySourceType.
202+
203+ Returns:
204+ Declared source method of this VulnerabilitySourceType as `VulnerabilitySourceType` or `None`.
205+ """
145206 return self ._method
146207
147208 def get_vector (self ) -> Union [str , None ]:
0 commit comments