1818
1919from collections .abc import Generator , Iterable
2020from datetime import datetime
21+ from enum import Enum
2122from itertools import chain
2223from typing import TYPE_CHECKING , Optional , Union
2324from uuid import UUID , uuid4
5657 from packageurl import PackageURL
5758
5859
60+ @serializable .serializable_enum
61+ class TlpClassification (str , Enum ):
62+ """
63+ Enum object that defines the Traffic Light Protocol (TLP) classification that controls the sharing and distribution
64+ of the data that the BOM describes.
65+
66+ .. note::
67+ Introduced in CycloneDX v1.7
68+
69+ .. note::
70+ See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.7/xml/#type_tlpClassificationType
71+ """
72+
73+ CLEAR = 'CLEAR'
74+ GREEN = 'GREEN'
75+ AMBER = 'AMBER'
76+ AMBER_AND_STRICT = 'AMBER_AND_STRICT'
77+ RED = 'RED'
78+
79+
80+ @serializable .serializable_class (ignore_unknown_during_deserialization = True )
81+ class DistributionConstraints :
82+ """
83+ Our internal representation of the `distributionConstraints` complex type.
84+ Conditions and constraints governing the sharing and distribution of the data or components described by this BOM.
85+
86+ .. note::
87+ Introduced in CycloneDX v1.7
88+
89+ .. note::
90+ See the CycloneDX Schema definition: https://cyclonedx.org/docs/1.7/xml/#type_metadata
91+ """
92+
93+ def __init__ (
94+ self , * ,
95+ tlp : Optional [TlpClassification ] = None ,
96+ ) -> None :
97+ self .tlp = tlp or TlpClassification .CLEAR
98+
99+ @property
100+ @serializable .xml_sequence (0 )
101+ def tlp (self ) -> TlpClassification :
102+ """
103+ The Traffic Light Protocol (TLP) classification that controls the sharing and distribution of the data that the
104+ BOM describes.
105+
106+ Returns:
107+ `TlpClassification` enum value
108+ """
109+ return self ._tlp
110+
111+ @tlp .setter
112+ def tlp (self , tlp : TlpClassification ) -> None :
113+ self ._tlp = tlp
114+
115+ def __comparable_tuple (self ) -> _ComparableTuple :
116+ return _ComparableTuple (self .tlp )
117+
118+ def __eq__ (self , other : object ) -> bool :
119+ if isinstance (other , DistributionConstraints ):
120+ return self .__comparable_tuple () == other .__comparable_tuple ()
121+ return False
122+
123+ def __lt__ (self , other : object ) -> bool :
124+ if isinstance (other , DistributionConstraints ):
125+ return self .__comparable_tuple () < other .__comparable_tuple ()
126+ return NotImplemented
127+
128+ def __hash__ (self ) -> int :
129+ return hash (self .__comparable_tuple ())
130+
131+ def __repr__ (self ) -> str :
132+ return f'<DistributionConstraints tlp={ self .tlp } >'
133+
134+
59135@serializable .serializable_class (ignore_unknown_during_deserialization = True )
60136class BomMetaData :
61137 """
@@ -76,6 +152,7 @@ def __init__(
76152 timestamp : Optional [datetime ] = None ,
77153 manufacturer : Optional [OrganizationalEntity ] = None ,
78154 lifecycles : Optional [Iterable [Lifecycle ]] = None ,
155+ distribution_constraints : Optional [DistributionConstraints ] = None ,
79156 # Deprecated as of v1.6
80157 manufacture : Optional [OrganizationalEntity ] = None ,
81158 ) -> None :
@@ -88,6 +165,7 @@ def __init__(
88165 self .properties = properties or []
89166 self .manufacturer = manufacturer
90167 self .lifecycles = lifecycles or []
168+ self .distribution_constraints = distribution_constraints
91169 # deprecated properties below
92170 self .manufacture = manufacture
93171
@@ -301,10 +379,27 @@ def properties(self) -> 'SortedSet[Property]':
301379 def properties (self , properties : Iterable [Property ]) -> None :
302380 self ._properties = SortedSet (properties )
303381
382+ @property
383+ @serializable .view (SchemaVersion1Dot7 )
384+ @serializable .xml_sequence (11 )
385+ def distribution_constraints (self ) -> Optional [DistributionConstraints ]:
386+ """
387+ Conditions and constraints governing the sharing and distribution of the data or components described by this
388+ BOM.
389+
390+ Returns:
391+ `DistributionConstraints` or `None`
392+ """
393+ return self ._distribution_constraints
394+
395+ @distribution_constraints .setter
396+ def distribution_constraints (self , distribution_constraints : Optional [DistributionConstraints ]) -> None :
397+ self ._distribution_constraints = distribution_constraints
398+
304399 def __comparable_tuple (self ) -> _ComparableTuple :
305400 return _ComparableTuple ((
306401 _ComparableTuple (self .authors ), self .component , _ComparableTuple (self .licenses ), self .manufacture ,
307- _ComparableTuple (self .properties ),
402+ _ComparableTuple (self .properties ), self . distribution_constraints ,
308403 _ComparableTuple (self .lifecycles ), self .supplier , self .timestamp , self .tools , self .manufacturer
309404 ))
310405
0 commit comments