Skip to content

Commit

Permalink
fix(#692): add crypto-ref-array to ProtocolProperties
Browse files Browse the repository at this point in the history
applied the fix recommended in the thread.
added testcase and BOM json from the mentioned issue.
  • Loading branch information
indiVar0508 committed Jan 30, 2025
1 parent b8cbb59 commit 300ad09
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 2 deletions.
28 changes: 27 additions & 1 deletion cyclonedx/model/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,13 @@ def __init__(
version: Optional[str] = None,
cipher_suites: Optional[Iterable[ProtocolPropertiesCipherSuite]] = None,
ikev2_transform_types: Optional[Ikev2TransformTypes] = None,
crypto_ref_array: Optional[Iterable[BomRef]] = None,
) -> None:
self.type = type
self.version = version
self.cipher_suites = cipher_suites or [] # type:ignore[assignment]
self.ikev2_transform_types = ikev2_transform_types
self.crypto_ref_array = crypto_ref_array or [] # type:ignore[assignment]

@property
@serializable.xml_sequence(10)
Expand Down Expand Up @@ -1376,13 +1378,37 @@ def ikev2_transform_types(self) -> Optional[Ikev2TransformTypes]:
def ikev2_transform_types(self, ikev2_transform_types: Optional[Ikev2TransformTypes]) -> None:
self._ikev2_transform_types = ikev2_transform_types

@property
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'cryptoRefArray')
@serializable.xml_sequence(40)
def crypto_ref_array(self) -> 'SortedSet[BomRef]':
"""
A list of protocol-related cryptographic assets.
Returns:
`Iterable[BomRef]`
"""
return self._crypto_ref_array

@crypto_ref_array.setter
def crypto_ref_array(self, crypto_ref_array: Iterable[BomRef]) -> None:
self._crypto_ref_array = SortedSet(crypto_ref_array)

def __eq__(self, other: object) -> bool:
if isinstance(other, ProtocolProperties):
return hash(other) == hash(self)
return False

def __hash__(self) -> int:
return hash((self.type, self.version, tuple(self.cipher_suites), self.ikev2_transform_types))
return hash(
(
self.type,
self.version,
tuple(self.cipher_suites),
self.ikev2_transform_types,
tuple(self.crypto_ref_array)
)
)

def __repr__(self) -> str:
return f'<ProtocolProperties type={self.type}, version={self.version}>'
Expand Down
170 changes: 170 additions & 0 deletions tests/_data/own/json/1.6/issue692.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion tests/test_deserialize_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test(ls: LicenseRepository) -> None:

def test_regression_issue690(self) -> None:
"""
regressio test for issue#690.
regression test for issue#690.
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/690
"""
json_file = join(OWN_DATA_DIRECTORY, 'json',
Expand All @@ -100,3 +100,16 @@ def test_regression_issue690(self) -> None:
json = json_loads(f.read())
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
self.assertIsNotNone(bom)

def test_regression_issue692(self) -> None:
"""
regression test for issue#692.
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/692
"""
json_file = join(OWN_DATA_DIRECTORY, 'json',
SchemaVersion.V1_6.to_version(),
'issue692.json')
with open(json_file) as f:
json = json_loads(f.read())
bom: Bom = Bom.from_json(json) # <<< is expected to not crash
self.assertIsNotNone(bom)

0 comments on commit 300ad09

Please sign in to comment.