Skip to content

Commit f9223d8

Browse files
authored
feat: ProtocolPropertiesType enum cases for CycloneDX 1.7 (#1003)
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 788ced1 commit f9223d8

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

cyclonedx/model/crypto.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,17 +1150,72 @@ class ProtocolPropertiesType(str, Enum):
11501150
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_cryptoPropertiesType
11511151
"""
11521152

1153+
DTLS = 'dtls' # since CDX1.7
1154+
EAP_AKA = 'eap-aka' # since CDX1.7
1155+
EAP_AKA_PRIME = 'eap-aka-prime' # since CDX1.7
1156+
FIVEG_AKA = '5g-aka' # since CDX1.7
11531157
IKE = 'ike'
11541158
IPSEC = 'ipsec'
1159+
PRINS = 'prins' # since CDX1.7
1160+
QUIC = 'quic' # since CDX1.7
11551161
SSH = 'ssh'
11561162
SSTP = 'sstp'
11571163
TLS = 'tls'
11581164
WPA = 'wpa'
1159-
1165+
# --
11601166
OTHER = 'other'
11611167
UNKNOWN = 'unknown'
11621168

11631169

1170+
class _ProtocolPropertiesTypeSerializationHelper(serializable.helpers.BaseHelper):
1171+
""" THIS CLASS IS NON-PUBLIC API """
1172+
1173+
__CASES: dict[type[serializable.ViewType], frozenset[ProtocolPropertiesType]] = dict()
1174+
__CASES[SchemaVersion1Dot6] = frozenset({
1175+
ProtocolPropertiesType.IKE,
1176+
ProtocolPropertiesType.IPSEC,
1177+
ProtocolPropertiesType.SSH,
1178+
ProtocolPropertiesType.SSTP,
1179+
ProtocolPropertiesType.TLS,
1180+
ProtocolPropertiesType.WPA,
1181+
ProtocolPropertiesType.OTHER,
1182+
ProtocolPropertiesType.UNKNOWN,
1183+
})
1184+
__CASES[SchemaVersion1Dot7] = __CASES[SchemaVersion1Dot6] | {
1185+
ProtocolPropertiesType.DTLS,
1186+
ProtocolPropertiesType.EAP_AKA,
1187+
ProtocolPropertiesType.EAP_AKA_PRIME,
1188+
ProtocolPropertiesType.PRINS,
1189+
ProtocolPropertiesType.QUIC,
1190+
}
1191+
1192+
@classmethod
1193+
def __normalize(cls, ppt: ProtocolPropertiesType, view: type[serializable.ViewType]) -> str:
1194+
return (
1195+
ppt
1196+
if ppt in cls.__CASES.get(view, ())
1197+
else ProtocolPropertiesType.OTHER
1198+
).value
1199+
1200+
@classmethod
1201+
def json_normalize(cls, o: Any, *,
1202+
view: Optional[type[serializable.ViewType]],
1203+
**__: Any) -> str:
1204+
assert view is not None
1205+
return cls.__normalize(o, view)
1206+
1207+
@classmethod
1208+
def xml_normalize(cls, o: Any, *,
1209+
view: Optional[type[serializable.ViewType]],
1210+
**__: Any) -> str:
1211+
assert view is not None
1212+
return cls.__normalize(o, view)
1213+
1214+
@classmethod
1215+
def deserialize(cls, o: Any) -> ProtocolPropertiesType:
1216+
return ProtocolPropertiesType(o)
1217+
1218+
11641219
@serializable.serializable_class(ignore_unknown_during_deserialization=True)
11651220
class ProtocolPropertiesCipherSuite:
11661221
"""
@@ -1430,6 +1485,7 @@ def __init__(
14301485
self.crypto_refs = crypto_refs or []
14311486

14321487
@property
1488+
@serializable.type_mapping(_ProtocolPropertiesTypeSerializationHelper)
14331489
@serializable.xml_sequence(10)
14341490
def type(self) -> Optional[ProtocolPropertiesType]:
14351491
"""

0 commit comments

Comments
 (0)