Skip to content

Commit ac2099e

Browse files
authored
Merge branch 'main' into refactor/streamline_comparisson_tuples
2 parents 744b230 + 6003feb commit ac2099e

File tree

17 files changed

+219
-182
lines changed

17 files changed

+219
-182
lines changed

cyclonedx/model/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class DataFlow(str, Enum):
6464
This is our internal representation of the dataFlowType simple type within the CycloneDX standard.
6565
6666
.. note::
67-
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/xml/#type_dataFlowType
67+
See the CycloneDX Schema: https://cyclonedx.org/docs/1.6/xml/#type_dataFlowType
6868
"""
6969
INBOUND = 'inbound'
7070
OUTBOUND = 'outbound'
@@ -82,7 +82,7 @@ class DataClassification:
8282
8383
.. note::
8484
See the CycloneDX Schema for dataClassificationType:
85-
https://cyclonedx.org/docs/1.4/xml/#type_dataClassificationType
85+
https://cyclonedx.org/docs/1.6/xml/#type_dataClassificationType
8686
"""
8787

8888
def __init__(
@@ -161,7 +161,7 @@ class Encoding(str, Enum):
161161
This is our internal representation of the encoding simple type within the CycloneDX standard.
162162
163163
.. note::
164-
See the CycloneDX Schema: https://cyclonedx.org/docs/1.4/#type_encoding
164+
See the CycloneDX Schema: https://cyclonedx.org/docs/1.6/#type_encoding
165165
"""
166166
BASE_64 = 'base64'
167167

@@ -172,7 +172,7 @@ class AttachedText:
172172
This is our internal representation of the `attachedTextType` complex type within the CycloneDX standard.
173173
174174
.. note::
175-
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.3/#type_attachedTextType
175+
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.6/#type_attachedTextType
176176
"""
177177

178178
DEFAULT_CONTENT_TYPE = 'text/plain'
@@ -265,7 +265,7 @@ class HashAlgorithm(str, Enum):
265265
This is our internal representation of the hashAlg simple type within the CycloneDX standard.
266266
267267
.. note::
268-
See the CycloneDX Schema: https://cyclonedx.org/docs/1.3/#type_hashAlg
268+
See the CycloneDX Schema: https://cyclonedx.org/docs/1.6/#type_hashAlg
269269
"""
270270
# see `_HashTypeRepositorySerializationHelper.__CASES` for view/case map
271271
BLAKE2B_256 = 'BLAKE2b-256' # Only supported in >= 1.2
@@ -388,7 +388,7 @@ class HashType:
388388
This is our internal representation of the hashType complex type within the CycloneDX standard.
389389
390390
.. note::
391-
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.3/#type_hashType
391+
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.6/#type_hashType
392392
"""
393393

394394
@staticmethod
@@ -545,7 +545,7 @@ class ExternalReferenceType(str, Enum):
545545
Enum object that defines the permissible 'types' for an External Reference according to the CycloneDX schema.
546546
547547
.. note::
548-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_externalReferenceType
548+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/#type_externalReferenceType
549549
"""
550550
# see `_ExternalReferenceSerializationHelper.__CASES` for view/case map
551551
ADVERSARY_MODEL = 'adversary-model' # Only supported in >= 1.5
@@ -813,7 +813,7 @@ class ExternalReference:
813813
a CycloneDX BOM document.
814814
815815
.. note::
816-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_externalReference
816+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/#type_externalReference
817817
"""
818818

819819
def __init__(
@@ -927,7 +927,7 @@ class Property:
927927
a CycloneDX BOM document.
928928
929929
.. note::
930-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_propertyType
930+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_propertyType
931931
932932
Specifies an individual property with a name and value.
933933
"""
@@ -1002,7 +1002,7 @@ class NoteText:
10021002
a CycloneDX BOM document.
10031003
10041004
.. note::
1005-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_releaseNotesType
1005+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_releaseNotesType
10061006
"""
10071007

10081008
DEFAULT_CONTENT_TYPE: str = 'text/plain'
@@ -1094,7 +1094,7 @@ class Note:
10941094
a CycloneDX BOM document.
10951095
10961096
.. note::
1097-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_releaseNotesType
1097+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_releaseNotesType
10981098
10991099
@todo: Replace ``NoteText`` with ``AttachedText``?
11001100
"""
@@ -1178,7 +1178,7 @@ class IdentifiableAction:
11781178
This is our internal representation of the `identifiableActionType` complex type.
11791179
11801180
.. note::
1181-
See the CycloneDX specification: https://cyclonedx.org/docs/1.4/xml/#type_identifiableActionType
1181+
See the CycloneDX specification: https://cyclonedx.org/docs/1.6/xml/#type_identifiableActionType
11821182
"""
11831183

11841184
def __init__(
@@ -1269,7 +1269,7 @@ class Copyright:
12691269
This is our internal representation of the `copyrightsType` complex type.
12701270
12711271
.. note::
1272-
See the CycloneDX specification: https://cyclonedx.org/docs/1.4/xml/#type_copyrightsType
1272+
See the CycloneDX specification: https://cyclonedx.org/docs/1.6/xml/#type_copyrightsType
12731273
"""
12741274

12751275
def __init__(

cyclonedx/model/bom.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
SchemaVersion1Dot5,
3737
SchemaVersion1Dot6,
3838
)
39-
from ..serialization import LicenseRepositoryHelper, UrnUuidHelper
39+
from ..serialization import UrnUuidHelper
4040
from . import _BOM_LINK_PREFIX, ExternalReference, Property
4141
from .bom_ref import BomRef
4242
from .component import Component
4343
from .contact import OrganizationalContact, OrganizationalEntity
4444
from .definition import Definitions
4545
from .dependency import Dependable, Dependency
46-
from .license import License, LicenseExpression, LicenseRepository
46+
from .license import License, LicenseExpression, LicenseRepository, _LicenseRepositorySerializationHelper
4747
from .lifecycle import Lifecycle, LifecycleRepository, _LifecycleRepositoryHelper
4848
from .service import Service
4949
from .tool import Tool, ToolRepository, _ToolRepositoryHelper
@@ -61,7 +61,7 @@ class BomMetaData:
6161
This is our internal representation of the metadata complex type within the CycloneDX standard.
6262
6363
.. note::
64-
See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.5/#type_metadata
64+
See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.6/#type_metadata
6565
"""
6666

6767
def __init__(
@@ -256,7 +256,7 @@ def supplier(self, supplier: Optional[OrganizationalEntity]) -> None:
256256
@serializable.view(SchemaVersion1Dot4)
257257
@serializable.view(SchemaVersion1Dot5)
258258
@serializable.view(SchemaVersion1Dot6)
259-
@serializable.type_mapping(LicenseRepositoryHelper)
259+
@serializable.type_mapping(_LicenseRepositorySerializationHelper)
260260
@serializable.xml_sequence(9)
261261
def licenses(self) -> LicenseRepository:
262262
"""
@@ -400,7 +400,7 @@ def metadata(self) -> BomMetaData:
400400
Metadata object instance for this Bom.
401401
402402
.. note::
403-
See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.3/#type_metadata
403+
See the CycloneDX Schema for Bom metadata: https://cyclonedx.org/docs/1.6/#type_metadata
404404
"""
405405
return self._metadata
406406

cyclonedx/model/bom_ref.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
# Copyright (c) OWASP Foundation. All Rights Reserved.
1717

1818

19-
from typing import Any, Optional
19+
from typing import TYPE_CHECKING, Any, Optional
2020

21+
import serializable
2122

22-
class BomRef:
23+
from ..exception.serialization import CycloneDxDeserializationException, SerializationOfUnexpectedValueException
24+
25+
if TYPE_CHECKING: # pragma: no cover
26+
from typing import Type, TypeVar
27+
28+
_T_BR = TypeVar('_T_BR', bound='BomRef')
29+
30+
31+
@serializable.serializable_class
32+
class BomRef(serializable.helpers.BaseHelper):
2333
"""
2434
An identifier that can be used to reference objects elsewhere in the BOM.
2535
@@ -33,6 +43,8 @@ def __init__(self, value: Optional[str] = None) -> None:
3343
self.value = value
3444

3545
@property
46+
@serializable.json_name('.')
47+
@serializable.xml_name('.')
3648
def value(self) -> Optional[str]:
3749
return self._value
3850

@@ -67,3 +79,23 @@ def __str__(self) -> str:
6779

6880
def __bool__(self) -> bool:
6981
return self._value is not None
82+
83+
# region impl BaseHelper
84+
85+
@classmethod
86+
def serialize(cls, o: Any) -> Optional[str]:
87+
if isinstance(o, cls):
88+
return o.value
89+
raise SerializationOfUnexpectedValueException(
90+
f'Attempt to serialize a non-BomRef: {o!r}')
91+
92+
@classmethod
93+
def deserialize(cls: 'Type[_T_BR]', o: Any) -> '_T_BR':
94+
try:
95+
return cls(value=str(o))
96+
except ValueError as err:
97+
raise CycloneDxDeserializationException(
98+
f'BomRef string supplied does not parse: {o!r}'
99+
) from err
100+
101+
# endregion impl BaseHelper

cyclonedx/model/component.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
SchemaVersion1Dot5,
4545
SchemaVersion1Dot6,
4646
)
47-
from ..serialization import BomRefHelper, LicenseRepositoryHelper, PackageUrl as PackageUrlSH
47+
from ..serialization import PackageUrl as PackageUrlSH
4848
from . import (
4949
AttachedText,
5050
Copyright,
@@ -61,7 +61,7 @@
6161
from .crypto import CryptoProperties
6262
from .dependency import Dependable
6363
from .issue import IssueType
64-
from .license import License, LicenseRepository
64+
from .license import License, LicenseRepository, _LicenseRepositorySerializationHelper
6565
from .release_note import ReleaseNotes
6666

6767

@@ -71,7 +71,7 @@ class Commit:
7171
Our internal representation of the `commitType` complex type.
7272
7373
.. note::
74-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_commitType
74+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_commitType
7575
"""
7676

7777
def __init__(
@@ -201,7 +201,7 @@ class ComponentEvidence:
201201
Provides the ability to document evidence collected through various forms of extraction or analysis.
202202
203203
.. note::
204-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_componentEvidenceType
204+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_componentEvidenceType
205205
"""
206206

207207
def __init__(
@@ -251,7 +251,7 @@ def __init__(
251251
# ... # TODO since CDX1.5
252252

253253
@property
254-
@serializable.type_mapping(LicenseRepositoryHelper)
254+
@serializable.type_mapping(_LicenseRepositorySerializationHelper)
255255
@serializable.xml_sequence(4)
256256
def licenses(self) -> LicenseRepository:
257257
"""
@@ -306,7 +306,7 @@ class ComponentScope(str, Enum):
306306
Enum object that defines the permissable 'scopes' for a Component according to the CycloneDX schema.
307307
308308
.. note::
309-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_scope
309+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/#type_scope
310310
"""
311311
# see `_ComponentScopeSerializationHelper.__CASES` for view/case map
312312
REQUIRED = 'required'
@@ -362,7 +362,7 @@ class ComponentType(str, Enum):
362362
Enum object that defines the permissible 'types' for a Component according to the CycloneDX schema.
363363
364364
.. note::
365-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_classification
365+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/#type_classification
366366
"""
367367
# see `_ComponentTypeSerializationHelper.__CASES` for view/case map
368368
APPLICATION = 'application'
@@ -441,7 +441,7 @@ class Diff:
441441
Our internal representation of the `diffType` complex type.
442442
443443
.. note::
444-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_diffType
444+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_diffType
445445
"""
446446

447447
def __init__(
@@ -513,7 +513,7 @@ class PatchClassification(str, Enum):
513513
Enum object that defines the permissible `patchClassification`s.
514514
515515
.. note::
516-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_patchClassification
516+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_patchClassification
517517
"""
518518
BACKPORT = 'backport'
519519
CHERRY_PICK = 'cherry-pick'
@@ -527,7 +527,7 @@ class Patch:
527527
Our internal representation of the `patchType` complex type.
528528
529529
.. note::
530-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_patchType
530+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_patchType
531531
"""
532532

533533
def __init__(
@@ -621,7 +621,7 @@ class Pedigree:
621621
may not be known.
622622
623623
.. note::
624-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_pedigreeType
624+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_pedigreeType
625625
"""
626626

627627
def __init__(
@@ -779,7 +779,7 @@ class Swid:
779779
Our internal representation of the `swidType` complex type.
780780
781781
.. note::
782-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_swidType
782+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_swidType
783783
"""
784784

785785
def __init__(
@@ -1040,7 +1040,7 @@ class Component(Dependable):
10401040
This is our internal representation of a Component within a Bom.
10411041
10421042
.. note::
1043-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.3/#type_component
1043+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/#type_component
10441044
"""
10451045

10461046
@staticmethod
@@ -1182,7 +1182,7 @@ def mime_type(self, mime_type: Optional[str]) -> None:
11821182

11831183
@property
11841184
@serializable.json_name('bom-ref')
1185-
@serializable.type_mapping(BomRefHelper)
1185+
@serializable.type_mapping(BomRef)
11861186
@serializable.view(SchemaVersion1Dot1)
11871187
@serializable.view(SchemaVersion1Dot2)
11881188
@serializable.view(SchemaVersion1Dot3)
@@ -1418,7 +1418,7 @@ def hashes(self, hashes: Iterable[HashType]) -> None:
14181418
@serializable.view(SchemaVersion1Dot4)
14191419
@serializable.view(SchemaVersion1Dot5)
14201420
@serializable.view(SchemaVersion1Dot6)
1421-
@serializable.type_mapping(LicenseRepositoryHelper)
1421+
@serializable.type_mapping(_LicenseRepositorySerializationHelper)
14221422
@serializable.xml_sequence(12)
14231423
def licenses(self) -> LicenseRepository:
14241424
"""

cyclonedx/model/contact.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from .._internal.compare import ComparableTuple as _ComparableTuple
2626
from ..exception.model import NoPropertiesProvidedException
2727
from ..schema.schema import SchemaVersion1Dot6
28-
from ..serialization import BomRefHelper
2928
from . import XsUri
3029
from .bom_ref import BomRef
3130

@@ -60,7 +59,7 @@ def __init__(
6059

6160
@property
6261
@serializable.json_name('bom-ref')
63-
@serializable.type_mapping(BomRefHelper)
62+
@serializable.type_mapping(BomRef)
6463
@serializable.xml_attribute()
6564
@serializable.xml_name('bom-ref')
6665
def bom_ref(self) -> Optional[BomRef]:
@@ -195,7 +194,7 @@ class OrganizationalContact:
195194
within a CycloneDX BOM document.
196195
197196
.. note::
198-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_organizationalContact
197+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_organizationalContact
199198
"""
200199

201200
def __init__(
@@ -289,7 +288,7 @@ class OrganizationalEntity:
289288
within a CycloneDX BOM document.
290289
291290
.. note::
292-
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.4/xml/#type_organizationalEntity
291+
See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.6/xml/#type_organizationalEntity
293292
"""
294293

295294
def __init__(

0 commit comments

Comments
 (0)