Skip to content

Commit 3395fda

Browse files
feat: add support for component's evidences according to spec (#810)
fixes #737 --------- Signed-off-by: Arun <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Jan Kowalleck <[email protected]>
1 parent 60edf77 commit 3395fda

18 files changed

+1969
-139
lines changed

cyclonedx/exception/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class CycloneDxModelException(CycloneDxException):
3030
pass
3131

3232

33+
class InvalidValueException(CycloneDxModelException):
34+
pass
35+
36+
3337
class InvalidLocaleTypeException(CycloneDxModelException):
3438
"""
3539
Raised when the supplied locale does not conform to ISO-639 specification.
@@ -131,3 +135,11 @@ class InvalidCreIdException(CycloneDxModelException):
131135
as defined at https://opencre.org/
132136
"""
133137
pass
138+
139+
140+
class InvalidConfidenceException(CycloneDxModelException):
141+
"""
142+
Raised when an invalid value is provided for a Confidence.
143+
The confidence of the evidence from 0 - 1, where 1 is 100% confidence.
144+
"""
145+
pass

cyclonedx/model/component.py

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from ..serialization import PackageUrl as PackageUrlSH
4949
from . import (
5050
AttachedText,
51-
Copyright,
5251
ExternalReference,
5352
HashAlgorithm,
5453
HashType,
@@ -58,6 +57,7 @@
5857
_HashTypeRepositorySerializationHelper,
5958
)
6059
from .bom_ref import BomRef
60+
from .component_evidence import ComponentEvidence, _ComponentEvidenceSerializationHelper
6161
from .contact import OrganizationalContact, OrganizationalEntity
6262
from .crypto import CryptoProperties
6363
from .dependency import Dependable
@@ -191,108 +191,6 @@ def __repr__(self) -> str:
191191
return f'<Commit uid={self.uid}, url={self.url}, message={self.message}>'
192192

193193

194-
@serializable.serializable_class
195-
class ComponentEvidence:
196-
"""
197-
Our internal representation of the `componentEvidenceType` complex type.
198-
199-
Provides the ability to document evidence collected through various forms of extraction or analysis.
200-
201-
.. note::
202-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_componentEvidenceType
203-
"""
204-
205-
def __init__(
206-
self, *,
207-
licenses: Optional[Iterable[License]] = None,
208-
copyright: Optional[Iterable[Copyright]] = None,
209-
) -> None:
210-
self.licenses = licenses or []
211-
self.copyright = copyright or []
212-
213-
# @property
214-
# ...
215-
# @serializable.view(SchemaVersion1Dot5)
216-
# @serializable.xml_sequence(1)
217-
# def identity(self) -> ...:
218-
# ... # TODO since CDX1.5
219-
#
220-
# @identity.setter
221-
# def identity(self, ...) -> None:
222-
# ... # TODO since CDX1.5
223-
224-
# @property
225-
# ...
226-
# @serializable.view(SchemaVersion1Dot5)
227-
# @serializable.xml_sequence(2)
228-
# def occurrences(self) -> ...:
229-
# ... # TODO since CDX1.5
230-
#
231-
# @occurrences.setter
232-
# def occurrences(self, ...) -> None:
233-
# ... # TODO since CDX1.5
234-
235-
# @property
236-
# ...
237-
# @serializable.view(SchemaVersion1Dot5)
238-
# @serializable.xml_sequence(3)
239-
# def callstack(self) -> ...:
240-
# ... # TODO since CDX1.5
241-
#
242-
# @callstack.setter
243-
# def callstack(self, ...) -> None:
244-
# ... # TODO since CDX1.5
245-
246-
@property
247-
@serializable.type_mapping(_LicenseRepositorySerializationHelper)
248-
@serializable.xml_sequence(4)
249-
def licenses(self) -> LicenseRepository:
250-
"""
251-
Optional list of licenses obtained during analysis.
252-
253-
Returns:
254-
Set of `LicenseChoice`
255-
"""
256-
return self._licenses
257-
258-
@licenses.setter
259-
def licenses(self, licenses: Iterable[License]) -> None:
260-
self._licenses = LicenseRepository(licenses)
261-
262-
@property
263-
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'text')
264-
@serializable.xml_sequence(5)
265-
def copyright(self) -> 'SortedSet[Copyright]':
266-
"""
267-
Optional list of copyright statements.
268-
269-
Returns:
270-
Set of `Copyright`
271-
"""
272-
return self._copyright
273-
274-
@copyright.setter
275-
def copyright(self, copyright: Iterable[Copyright]) -> None:
276-
self._copyright = SortedSet(copyright)
277-
278-
def __comparable_tuple(self) -> _ComparableTuple:
279-
return _ComparableTuple((
280-
_ComparableTuple(self.licenses),
281-
_ComparableTuple(self.copyright),
282-
))
283-
284-
def __eq__(self, other: object) -> bool:
285-
if isinstance(other, ComponentEvidence):
286-
return self.__comparable_tuple() == other.__comparable_tuple()
287-
return False
288-
289-
def __hash__(self) -> int:
290-
return hash(self.__comparable_tuple())
291-
292-
def __repr__(self) -> str:
293-
return f'<ComponentEvidence id={id(self)}>'
294-
295-
296194
@serializable.serializable_enum
297195
class ComponentScope(str, Enum):
298196
"""
@@ -1644,6 +1542,7 @@ def components(self, components: Iterable['Component']) -> None:
16441542
@serializable.view(SchemaVersion1Dot5)
16451543
@serializable.view(SchemaVersion1Dot6)
16461544
@serializable.xml_sequence(24)
1545+
@serializable.type_mapping(_ComponentEvidenceSerializationHelper)
16471546
def evidence(self) -> Optional[ComponentEvidence]:
16481547
"""
16491548
Provides the ability to document evidence collected through various forms of extraction or analysis.

0 commit comments

Comments
 (0)