Skip to content

Commit e02edcb

Browse files
committed
feat: ProtocolPropertiesType cases for CycloneDX 1.7
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent bdeaa91 commit e02edcb

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
@@ -1096,17 +1096,72 @@ class ProtocolPropertiesType(str, Enum):
10961096
See the CycloneDX Schema for hashType: https://cyclonedx.org/docs/1.7/xml/#type_cryptoPropertiesType
10971097
"""
10981098

1099+
DTLS = 'dtls' # since CDX1.7
1100+
EAP_AKA = 'eap-aka' # since CDX1.7
1101+
EAP_AKA_PRIME = 'eap-aka-prime' # since CDX1.7
1102+
FIVEG_AKA = '5g-aka' # since CDX1.7
10991103
IKE = 'ike'
11001104
IPSEC = 'ipsec'
1105+
PRINS = 'prins' # since CDX1.7
1106+
QUIC = 'quic' # since CDX1.7
11011107
SSH = 'ssh'
11021108
SSTP = 'sstp'
11031109
TLS = 'tls'
11041110
WPA = 'wpa'
1105-
1111+
# --
11061112
OTHER = 'other'
11071113
UNKNOWN = 'unknown'
11081114

11091115

1116+
class _ProtocolPropertiesTypeSerializationHelper(serializable.helpers.BaseHelper):
1117+
""" THIS CLASS IS NON-PUBLIC API """
1118+
1119+
__CASES: dict[type[serializable.ViewType], frozenset[ProtocolPropertiesType]] = dict()
1120+
__CASES[SchemaVersion1Dot6] = frozenset({
1121+
ProtocolPropertiesType.IKE,
1122+
ProtocolPropertiesType.IPSEC,
1123+
ProtocolPropertiesType.SSH,
1124+
ProtocolPropertiesType.SSTP,
1125+
ProtocolPropertiesType.TLS,
1126+
ProtocolPropertiesType.WPA,
1127+
ProtocolPropertiesType.OTHER,
1128+
ProtocolPropertiesType.UNKNOWN,
1129+
})
1130+
__CASES[SchemaVersion1Dot7] = __CASES[SchemaVersion1Dot6] | {
1131+
ProtocolPropertiesType.DTLS,
1132+
ProtocolPropertiesType.EAP_AKA,
1133+
ProtocolPropertiesType.EAP_AKA_PRIME,
1134+
ProtocolPropertiesType.PRINS,
1135+
ProtocolPropertiesType.QUIC,
1136+
}
1137+
1138+
@classmethod
1139+
def __normalize(cls, ppt: ProtocolPropertiesType, view: type[serializable.ViewType]) -> str:
1140+
return (
1141+
ppt
1142+
if ppt in cls.__CASES.get(view, ())
1143+
else ProtocolPropertiesType.OTHER
1144+
).value
1145+
1146+
@classmethod
1147+
def json_normalize(cls, o: Any, *,
1148+
view: Optional[type[serializable.ViewType]],
1149+
**__: Any) -> str:
1150+
assert view is not None
1151+
return cls.__normalize(o, view)
1152+
1153+
@classmethod
1154+
def xml_normalize(cls, o: Any, *,
1155+
view: Optional[type[serializable.ViewType]],
1156+
**__: Any) -> str:
1157+
assert view is not None
1158+
return cls.__normalize(o, view)
1159+
1160+
@classmethod
1161+
def deserialize(cls, o: Any) -> ProtocolPropertiesType:
1162+
return ProtocolPropertiesType(o)
1163+
1164+
11101165
@serializable.serializable_class(ignore_unknown_during_deserialization=True)
11111166
class ProtocolPropertiesCipherSuite:
11121167
"""
@@ -1376,6 +1431,7 @@ def __init__(
13761431
self.crypto_refs = crypto_refs or []
13771432

13781433
@property
1434+
@serializable.type_mapping(_ProtocolPropertiesTypeSerializationHelper)
13791435
@serializable.xml_sequence(10)
13801436
def type(self) -> Optional[ProtocolPropertiesType]:
13811437
"""

0 commit comments

Comments
 (0)