Skip to content

Commit 300ad09

Browse files
committed
fix(#692): add crypto-ref-array to ProtocolProperties
applied the fix recommended in the thread. added testcase and BOM json from the mentioned issue.
1 parent b8cbb59 commit 300ad09

File tree

3 files changed

+211
-2
lines changed

3 files changed

+211
-2
lines changed

cyclonedx/model/crypto.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,13 @@ def __init__(
13091309
version: Optional[str] = None,
13101310
cipher_suites: Optional[Iterable[ProtocolPropertiesCipherSuite]] = None,
13111311
ikev2_transform_types: Optional[Ikev2TransformTypes] = None,
1312+
crypto_ref_array: Optional[Iterable[BomRef]] = None,
13121313
) -> None:
13131314
self.type = type
13141315
self.version = version
13151316
self.cipher_suites = cipher_suites or [] # type:ignore[assignment]
13161317
self.ikev2_transform_types = ikev2_transform_types
1318+
self.crypto_ref_array = crypto_ref_array or [] # type:ignore[assignment]
13171319

13181320
@property
13191321
@serializable.xml_sequence(10)
@@ -1376,13 +1378,37 @@ def ikev2_transform_types(self) -> Optional[Ikev2TransformTypes]:
13761378
def ikev2_transform_types(self, ikev2_transform_types: Optional[Ikev2TransformTypes]) -> None:
13771379
self._ikev2_transform_types = ikev2_transform_types
13781380

1381+
@property
1382+
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'cryptoRefArray')
1383+
@serializable.xml_sequence(40)
1384+
def crypto_ref_array(self) -> 'SortedSet[BomRef]':
1385+
"""
1386+
A list of protocol-related cryptographic assets.
1387+
1388+
Returns:
1389+
`Iterable[BomRef]`
1390+
"""
1391+
return self._crypto_ref_array
1392+
1393+
@crypto_ref_array.setter
1394+
def crypto_ref_array(self, crypto_ref_array: Iterable[BomRef]) -> None:
1395+
self._crypto_ref_array = SortedSet(crypto_ref_array)
1396+
13791397
def __eq__(self, other: object) -> bool:
13801398
if isinstance(other, ProtocolProperties):
13811399
return hash(other) == hash(self)
13821400
return False
13831401

13841402
def __hash__(self) -> int:
1385-
return hash((self.type, self.version, tuple(self.cipher_suites), self.ikev2_transform_types))
1403+
return hash(
1404+
(
1405+
self.type,
1406+
self.version,
1407+
tuple(self.cipher_suites),
1408+
self.ikev2_transform_types,
1409+
tuple(self.crypto_ref_array)
1410+
)
1411+
)
13861412

13871413
def __repr__(self) -> str:
13881414
return f'<ProtocolProperties type={self.type}, version={self.version}>'

tests/_data/own/json/1.6/issue692.json

+170
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_deserialize_json.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test(ls: LicenseRepository) -> None:
9090

9191
def test_regression_issue690(self) -> None:
9292
"""
93-
regressio test for issue#690.
93+
regression test for issue#690.
9494
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/690
9595
"""
9696
json_file = join(OWN_DATA_DIRECTORY, 'json',
@@ -100,3 +100,16 @@ def test_regression_issue690(self) -> None:
100100
json = json_loads(f.read())
101101
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
102102
self.assertIsNotNone(bom)
103+
104+
def test_regression_issue692(self) -> None:
105+
"""
106+
regression test for issue#692.
107+
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/692
108+
"""
109+
json_file = join(OWN_DATA_DIRECTORY, 'json',
110+
SchemaVersion.V1_6.to_version(),
111+
'issue692.json')
112+
with open(json_file) as f:
113+
json = json_loads(f.read())
114+
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
115+
self.assertIsNotNone(bom)

0 commit comments

Comments
 (0)