@@ -59,6 +59,8 @@ class CryptoAssetType(str, Enum):
5959
6060@serializable .serializable_enum
6161class CryptoPrimitive (str , Enum ):
62+ # TODO: rename to `CryptoAlgorithmPrimitive`
63+
6264 """
6365 This is our internal representation of the cryptoPropertiesType.algorithmProperties.primitive ENUM type within the
6466 CycloneDX standard.
@@ -78,18 +80,73 @@ class CryptoPrimitive(str, Enum):
7880 KDF = 'kdf'
7981 KEM = 'kem'
8082 KEY_AGREE = 'key-agree'
83+ KEY_WRAP = 'key-wrap' # since CDX1.7
8184 MAC = 'mac'
8285 PKE = 'pke'
8386 SIGNATURE = 'signature'
8487 STREAM_CIPHER = 'stream-cipher'
8588 XOF = 'xof'
86-
89+ # --
8790 OTHER = 'other'
8891 UNKNOWN = 'unknown'
8992
9093
94+ class _CryptoPrimitiveSerializationHelper (serializable .helpers .BaseHelper ):
95+ """ THIS CLASS IS NON-PUBLIC API """
96+
97+ __CASES : dict [type [serializable .ViewType ], frozenset [CryptoPrimitive ]] = dict ()
98+ __CASES [SchemaVersion1Dot6 ] = frozenset ({
99+ CryptoPrimitive .AE ,
100+ CryptoPrimitive .BLOCK_CIPHER ,
101+ CryptoPrimitive .COMBINER ,
102+ CryptoPrimitive .DRBG ,
103+ CryptoPrimitive .HASH ,
104+ CryptoPrimitive .KDF ,
105+ CryptoPrimitive .KEM ,
106+ CryptoPrimitive .KEY_AGREE ,
107+ CryptoPrimitive .MAC ,
108+ CryptoPrimitive .PKE ,
109+ CryptoPrimitive .SIGNATURE ,
110+ CryptoPrimitive .STREAM_CIPHER ,
111+ CryptoPrimitive .XOF ,
112+ CryptoPrimitive .OTHER ,
113+ CryptoPrimitive .UNKNOWN ,
114+ })
115+ __CASES [SchemaVersion1Dot7 ] = __CASES [SchemaVersion1Dot6 ] | {
116+ CryptoPrimitive .KEY_WRAP ,
117+ }
118+
119+ @classmethod
120+ def __normalize (cls , cp : CryptoPrimitive , view : type [serializable .ViewType ]) -> str :
121+ return (
122+ cp
123+ if cp in cls .__CASES .get (view , ())
124+ else CryptoPrimitive .OTHER
125+ ).value
126+
127+ @classmethod
128+ def json_normalize (cls , o : Any , * ,
129+ view : Optional [type [serializable .ViewType ]],
130+ ** __ : Any ) -> str :
131+ assert view is not None
132+ return cls .__normalize (o , view )
133+
134+ @classmethod
135+ def xml_normalize (cls , o : Any , * ,
136+ view : Optional [type [serializable .ViewType ]],
137+ ** __ : Any ) -> str :
138+ assert view is not None
139+ return cls .__normalize (o , view )
140+
141+ @classmethod
142+ def deserialize (cls , o : Any ) -> CryptoPrimitive :
143+ return CryptoPrimitive (o )
144+
145+
91146@serializable .serializable_enum
92147class CryptoExecutionEnvironment (str , Enum ):
148+ # TODO: rename to `CryptoAlgorithmExecutionEnvironment`
149+
93150 """
94151 This is our internal representation of the cryptoPropertiesType.algorithmProperties.executionEnvironment ENUM type
95152 within the CycloneDX standard.
@@ -105,13 +162,15 @@ class CryptoExecutionEnvironment(str, Enum):
105162 SOFTWARE_ENCRYPTED_RAM = 'software-encrypted-ram'
106163 SOFTWARE_PLAIN_RAM = 'software-plain-ram'
107164 SOFTWARE_TEE = 'software-tee'
108-
165+ # --
109166 OTHER = 'other'
110167 UNKNOWN = 'unknown'
111168
112169
113170@serializable .serializable_enum
114171class CryptoImplementationPlatform (str , Enum ):
172+ # TODO: rename to `CryptoAlgorithmImplementationPlatform`
173+
115174 """
116175 This is our internal representation of the cryptoPropertiesType.algorithmProperties.implementationPlatform ENUM type
117176 within the CycloneDX standard.
@@ -129,19 +188,21 @@ class CryptoImplementationPlatform(str, Enum):
129188 ARMV8_M = 'armv8-m'
130189 ARMV9_A = 'armv9-a'
131190 ARMV9_M = 'armv9-m'
132- GENERIC = 'generic'
133191 PPC64 = 'ppc64'
134192 PPC64LE = 'ppc64le'
135193 S390X = 's390x'
136194 X86_32 = 'x86_32'
137195 X86_64 = 'x86_64'
138-
196+ # --
197+ GENERIC = 'generic'
139198 OTHER = 'other'
140199 UNKNOWN = 'unknown'
141200
142201
143202@serializable .serializable_enum
144203class CryptoCertificationLevel (str , Enum ):
204+ # TODO: rename to `CryptoAlgorithmCertificationLevel`
205+
145206 """
146207 This is our internal representation of the cryptoPropertiesType.algorithmProperties.certificationLevel ENUM type
147208 within the CycloneDX standard.
@@ -154,7 +215,7 @@ class CryptoCertificationLevel(str, Enum):
154215 """
155216
156217 NONE = 'none'
157-
218+ # --
158219 FIPS140_1_L1 = 'fips140-1-l1'
159220 FIPS140_1_L2 = 'fips140-1-l2'
160221 FIPS140_1_L3 = 'fips140-1-l3'
@@ -181,13 +242,15 @@ class CryptoCertificationLevel(str, Enum):
181242 CC_EAL6_PLUS = 'cc-eal6+'
182243 CC_EAL7 = 'cc-eal7'
183244 CC_EAL7_PLUS = 'cc-eal7+'
184-
245+ # --
185246 OTHER = 'other'
186247 UNKNOWN = 'unknown'
187248
188249
189250@serializable .serializable_enum
190251class CryptoMode (str , Enum ):
252+ # TODO: rename to `CryptoAlgorithmMode`
253+
191254 """
192255 This is our internal representation of the cryptoPropertiesType.algorithmProperties.mode ENUM type
193256 within the CycloneDX standard.
@@ -206,13 +269,15 @@ class CryptoMode(str, Enum):
206269 ECB = 'ecb'
207270 GCM = 'gcm'
208271 OFB = 'ofb'
209-
272+ # --
210273 OTHER = 'other'
211274 UNKNOWN = 'unknown'
212275
213276
214277@serializable .serializable_enum
215278class CryptoPadding (str , Enum ):
279+ # TODO: rename to `CryptoAlgorithmPadding`
280+
216281 """
217282 This is our internal representation of the cryptoPropertiesType.algorithmProperties.padding ENUM type
218283 within the CycloneDX standard.
@@ -229,7 +294,7 @@ class CryptoPadding(str, Enum):
229294 PKCS1V15 = 'pkcs1v15'
230295 OAEP = 'oaep'
231296 RAW = 'raw'
232-
297+ # --
233298 OTHER = 'other'
234299 UNKNOWN = 'unknown'
235300
@@ -258,7 +323,7 @@ class CryptoFunction(str, Enum):
258323 SIGN = 'sign'
259324 TAG = 'tag'
260325 VERIFY = 'verify'
261-
326+ # --
262327 OTHER = 'other'
263328 UNKNOWN = 'unknown'
264329
@@ -303,6 +368,7 @@ def __init__(
303368 self .nist_quantum_security_level = nist_quantum_security_level
304369
305370 @property
371+ @serializable .type_mapping (_CryptoPrimitiveSerializationHelper )
306372 @serializable .xml_sequence (1 )
307373 def primitive (self ) -> Optional [CryptoPrimitive ]:
308374 """
@@ -731,7 +797,7 @@ class RelatedCryptoMaterialType(str, Enum):
731797 SIGNATURE = 'signature'
732798 TAG = 'tag'
733799 TOKEN = 'token' # nosec
734-
800+ # --
735801 OTHER = 'other'
736802 UNKNOWN = 'unknown'
737803
@@ -1096,17 +1162,73 @@ class ProtocolPropertiesType(str, Enum):
10961162 See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_cryptoPropertiesType
10971163 """
10981164
1165+ DTLS = 'dtls' # since CDX1.7
1166+ EAP_AKA = 'eap-aka' # since CDX1.7
1167+ EAP_AKA_PRIME = 'eap-aka-prime' # since CDX1.7
1168+ FIVEG_AKA = '5g-aka' # since CDX1.7
10991169 IKE = 'ike'
11001170 IPSEC = 'ipsec'
1171+ PRINS = 'prins' # since CDX1.7
1172+ QUIC = 'quic' # since CDX1.7
11011173 SSH = 'ssh'
11021174 SSTP = 'sstp'
11031175 TLS = 'tls'
11041176 WPA = 'wpa'
1105-
1177+ # --
11061178 OTHER = 'other'
11071179 UNKNOWN = 'unknown'
11081180
11091181
1182+ class _ProtocolPropertiesTypeSerializationHelper (serializable .helpers .BaseHelper ):
1183+ """ THIS CLASS IS NON-PUBLIC API """
1184+
1185+ __CASES : dict [type [serializable .ViewType ], frozenset [ProtocolPropertiesType ]] = dict ()
1186+ __CASES [SchemaVersion1Dot6 ] = frozenset ({
1187+ ProtocolPropertiesType .IKE ,
1188+ ProtocolPropertiesType .IPSEC ,
1189+ ProtocolPropertiesType .SSH ,
1190+ ProtocolPropertiesType .SSTP ,
1191+ ProtocolPropertiesType .TLS ,
1192+ ProtocolPropertiesType .WPA ,
1193+ ProtocolPropertiesType .OTHER ,
1194+ ProtocolPropertiesType .UNKNOWN ,
1195+ })
1196+ __CASES [SchemaVersion1Dot7 ] = __CASES [SchemaVersion1Dot6 ] | {
1197+ ProtocolPropertiesType .DTLS ,
1198+ ProtocolPropertiesType .EAP_AKA ,
1199+ ProtocolPropertiesType .EAP_AKA_PRIME ,
1200+ ProtocolPropertiesType .FIVEG_AKA ,
1201+ ProtocolPropertiesType .PRINS ,
1202+ ProtocolPropertiesType .QUIC ,
1203+ }
1204+
1205+ @classmethod
1206+ def __normalize (cls , ppt : ProtocolPropertiesType , view : type [serializable .ViewType ]) -> str :
1207+ return (
1208+ ppt
1209+ if ppt in cls .__CASES .get (view , ())
1210+ else ProtocolPropertiesType .OTHER
1211+ ).value
1212+
1213+ @classmethod
1214+ def json_normalize (cls , o : Any , * ,
1215+ view : Optional [type [serializable .ViewType ]],
1216+ ** __ : Any ) -> str :
1217+ assert view is not None
1218+ return cls .__normalize (o , view )
1219+
1220+ @classmethod
1221+ def xml_normalize (cls , o : Any , * ,
1222+ view : Optional [type [serializable .ViewType ]],
1223+ ** __ : Any ) -> str :
1224+ assert view is not None
1225+ return cls .__normalize (o , view )
1226+
1227+ @classmethod
1228+ def deserialize (cls , o : Any ) -> ProtocolPropertiesType :
1229+ return ProtocolPropertiesType (o )
1230+
1231+
11101232@serializable .serializable_class (ignore_unknown_during_deserialization = True )
11111233class ProtocolPropertiesCipherSuite :
11121234 """
@@ -1376,6 +1498,7 @@ def __init__(
13761498 self .crypto_refs = crypto_refs or []
13771499
13781500 @property
1501+ @serializable .type_mapping (_ProtocolPropertiesTypeSerializationHelper )
13791502 @serializable .xml_sequence (10 )
13801503 def type (self ) -> Optional [ProtocolPropertiesType ]:
13811504 """
0 commit comments