Skip to content

Commit 3583283

Browse files
committed
feat: add cyclonedx.model.crypto.ProtocolProperties.crypto_ref_array
applied the fix recommended in the thread, to add crypto_ref_array as an argument to ProtocolProperties class Also updated bom1.6.SNAPSHOT.xsd from cryptoRef -> cryptoRefArray added testcase and BOM json from the mentioned issue. Signed-off-by: Indivar Mishra <[email protected]>
1 parent 472bded commit 3583283

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
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}>'

cyclonedx/schema/_res/bom-1.6.SNAPSHOT.xsd

+1-1
Original file line numberDiff line numberDiff line change
@@ -7429,7 +7429,7 @@ limitations under the License.
74297429
</xs:sequence>
74307430
</xs:complexType>
74317431
</xs:element>
7432-
<xs:element name="cryptoRef" type="bom:refType" minOccurs="0" maxOccurs="unbounded">
7432+
<xs:element name="cryptoRefArray" type="bom:refType" minOccurs="0" maxOccurs="unbounded">
74337433
<xs:annotation>
74347434
<xs:documentation>A protocol-related cryptographic assets</xs:documentation>
74357435
</xs:annotation>

tests/_data/models.py

+28
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,33 @@ def get_bom_for_issue_328_components() -> Bom:
708708
return bom
709709

710710

711+
def get_bom_for_issue_692_components() -> Bom:
712+
"""regression test for issue #692
713+
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/692
714+
"""
715+
bom = _make_bom()
716+
717+
comp_root = Component(type=ComponentType.APPLICATION,
718+
name='my application', version='1')
719+
comp_test = Component(
720+
name='comp_test',
721+
type=ComponentType.CRYPTOGRAPHIC_ASSET,
722+
bom_ref='crypto/protocol/test',
723+
crypto_properties=CryptoProperties(
724+
asset_type=CryptoAssetType.PROTOCOL,
725+
protocol_properties=ProtocolProperties(
726+
type=ProtocolPropertiesType.TLS,
727+
version='1.2',
728+
crypto_ref_array=[BomRef(value='for-test')]
729+
),
730+
oid='1.3.18.0.2.32.104',
731+
))
732+
bom.metadata.component = comp_root
733+
bom.register_dependency(comp_root, [comp_test])
734+
bom.components = [comp_test]
735+
return bom
736+
737+
711738
def get_component_setuptools_complete(include_pedigree: bool = True) -> Component:
712739
component = get_component_setuptools_simple(bom_ref='my-specific-bom-ref-for-dings')
713740
component.supplier = get_org_entity_1()
@@ -1357,4 +1384,5 @@ def get_bom_with_definitions_standards() -> Bom:
13571384
get_bom_for_issue_630_empty_property,
13581385
get_bom_with_lifecycles,
13591386
get_bom_with_definitions_standards,
1387+
get_bom_for_issue_692_components,
13601388
}

tests/test_deserialize_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_regression_issue764(self) -> None:
103103

104104
def test_regression_issue690(self) -> None:
105105
"""
106-
regressio test for issue#690.
106+
regression test for issue#690.
107107
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/690
108108
"""
109109
json_file = join(OWN_DATA_DIRECTORY, 'json',

0 commit comments

Comments
 (0)