Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion cyclonedx/model/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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]:
"""
Expand Down
Loading