From e02edcbaaf15d9c122b3eda4adbdb46a3d335f3a Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Wed, 17 Jun 2026 12:06:07 +0200 Subject: [PATCH] feat: ProtocolPropertiesType cases for CycloneDX 1.7 Signed-off-by: Jan Kowalleck --- cyclonedx/model/crypto.py | 58 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/cyclonedx/model/crypto.py b/cyclonedx/model/crypto.py index a3d32d0ea..3af18a09e 100644 --- a/cyclonedx/model/crypto.py +++ b/cyclonedx/model/crypto.py @@ -1096,17 +1096,72 @@ class ProtocolPropertiesType(str, Enum): See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_cryptoPropertiesType """ + DTLS = 'dtls' # since CDX1.7 + EAP_AKA = 'eap-aka' # since CDX1.7 + EAP_AKA_PRIME = 'eap-aka-prime' # since CDX1.7 + FIVEG_AKA = '5g-aka' # since CDX1.7 IKE = 'ike' IPSEC = 'ipsec' + PRINS = 'prins' # since CDX1.7 + QUIC = 'quic' # since CDX1.7 SSH = 'ssh' SSTP = 'sstp' TLS = 'tls' WPA = 'wpa' - + # -- OTHER = 'other' UNKNOWN = 'unknown' +class _ProtocolPropertiesTypeSerializationHelper(serializable.helpers.BaseHelper): + """ THIS CLASS IS NON-PUBLIC API """ + + __CASES: dict[type[serializable.ViewType], frozenset[ProtocolPropertiesType]] = dict() + __CASES[SchemaVersion1Dot6] = frozenset({ + ProtocolPropertiesType.IKE, + ProtocolPropertiesType.IPSEC, + ProtocolPropertiesType.SSH, + ProtocolPropertiesType.SSTP, + ProtocolPropertiesType.TLS, + ProtocolPropertiesType.WPA, + ProtocolPropertiesType.OTHER, + ProtocolPropertiesType.UNKNOWN, + }) + __CASES[SchemaVersion1Dot7] = __CASES[SchemaVersion1Dot6] | { + ProtocolPropertiesType.DTLS, + ProtocolPropertiesType.EAP_AKA, + ProtocolPropertiesType.EAP_AKA_PRIME, + ProtocolPropertiesType.PRINS, + ProtocolPropertiesType.QUIC, + } + + @classmethod + def __normalize(cls, ppt: ProtocolPropertiesType, view: type[serializable.ViewType]) -> str: + return ( + ppt + if ppt in cls.__CASES.get(view, ()) + else ProtocolPropertiesType.OTHER + ).value + + @classmethod + def json_normalize(cls, o: Any, *, + view: Optional[type[serializable.ViewType]], + **__: Any) -> str: + assert view is not None + return cls.__normalize(o, view) + + @classmethod + def xml_normalize(cls, o: Any, *, + view: Optional[type[serializable.ViewType]], + **__: Any) -> str: + assert view is not None + return cls.__normalize(o, view) + + @classmethod + def deserialize(cls, o: Any) -> ProtocolPropertiesType: + return ProtocolPropertiesType(o) + + @serializable.serializable_class(ignore_unknown_during_deserialization=True) class ProtocolPropertiesCipherSuite: """ @@ -1376,6 +1431,7 @@ def __init__( self.crypto_refs = crypto_refs or [] @property + @serializable.type_mapping(_ProtocolPropertiesTypeSerializationHelper) @serializable.xml_sequence(10) def type(self) -> Optional[ProtocolPropertiesType]: """