diff --git a/cyclonedx/model/crypto.py b/cyclonedx/model/crypto.py index 46dbf46d..f0d069f1 100644 --- a/cyclonedx/model/crypto.py +++ b/cyclonedx/model/crypto.py @@ -1150,17 +1150,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: """ @@ -1430,6 +1485,7 @@ def __init__( self.crypto_refs = crypto_refs or [] @property + @serializable.type_mapping(_ProtocolPropertiesTypeSerializationHelper) @serializable.xml_sequence(10) def type(self) -> Optional[ProtocolPropertiesType]: """