Skip to content

Commit 15e350a

Browse files
committed
wip
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent fc9befd commit 15e350a

11 files changed

+257
-172
lines changed

cyclonedx/model/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def content(self, content: str) -> None:
239239

240240
def __comparable_tuple(self) -> _ComparableTuple:
241241
return _ComparableTuple((
242-
self.content_type, self.content, self.encoding
242+
self.content_type, self.encoding, self.content,
243243
))
244244

245245
def __eq__(self, other: object) -> bool:

cyclonedx/model/component.py

+38-17
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def message(self, message: Optional[str]) -> None:
173173

174174
def __comparable_tuple(self) -> _ComparableTuple:
175175
return _ComparableTuple((
176-
self.uid, self.url, self.author, self.committer, self.message
176+
self.uid, self.url,
177+
self.author, self.committer,
178+
self.message
177179
))
178180

179181
def __eq__(self, other: object) -> bool:
@@ -487,7 +489,8 @@ def url(self, url: Optional[XsUri]) -> None:
487489

488490
def __comparable_tuple(self) -> _ComparableTuple:
489491
return _ComparableTuple((
490-
self.text, self.url
492+
self.url,
493+
self.text,
491494
))
492495

493496
def __eq__(self, other: object) -> bool:
@@ -590,7 +593,8 @@ def resolves(self, resolves: Iterable[IssueType]) -> None:
590593

591594
def __comparable_tuple(self) -> _ComparableTuple:
592595
return _ComparableTuple((
593-
self.type, self.diff, _ComparableTuple(self.resolves)
596+
self.type, self.diff,
597+
_ComparableTuple(self.resolves)
594598
))
595599

596600
def __eq__(self, other: object) -> bool:
@@ -757,17 +761,23 @@ def notes(self) -> Optional[str]:
757761
def notes(self, notes: Optional[str]) -> None:
758762
self._notes = notes
759763

764+
def __comparable_tuple(self) -> _ComparableTuple:
765+
return _ComparableTuple((
766+
_ComparableTuple(self.ancestors),
767+
_ComparableTuple(self.descendants),
768+
_ComparableTuple(self.variants),
769+
_ComparableTuple(self.commits),
770+
_ComparableTuple(self.patches),
771+
self.notes
772+
))
773+
760774
def __eq__(self, other: object) -> bool:
761775
if isinstance(other, Pedigree):
762-
return hash(other) == hash(self)
776+
return self.__comparable_tuple() == other.__comparable_tuple()
763777
return False
764778

765779
def __hash__(self) -> int:
766-
# TODO
767-
return hash((
768-
tuple(self.ancestors), tuple(self.descendants), tuple(self.variants), tuple(self.commits),
769-
tuple(self.patches), self.notes
770-
))
780+
return hash(self.__comparable_tuple())
771781

772782
def __repr__(self) -> str:
773783
return f'<Pedigree id={id(self)}, hash={hash(self)}>'
@@ -903,14 +913,23 @@ def url(self) -> Optional[XsUri]:
903913
def url(self, url: Optional[XsUri]) -> None:
904914
self._url = url
905915

916+
def __comparable_tuple(self) -> _ComparableTuple:
917+
return _ComparableTuple((
918+
self.tag_id,
919+
self.name, self.version,
920+
self.tag_version,
921+
self.patch,
922+
self.url,
923+
self.text,
924+
))
925+
906926
def __eq__(self, other: object) -> bool:
907927
if isinstance(other, Swid):
908-
return hash(other) == hash(self)
928+
return self.__comparable_tuple() == other.__comparable_tuple()
909929
return False
910930

911931
def __hash__(self) -> int:
912-
# TODO
913-
return hash((self.tag_id, self.name, self.version, self.tag_version, self.patch, self.text, self.url))
932+
return hash(self.__comparable_tuple())
914933

915934
def __repr__(self) -> str:
916935
return f'<Swid tagId={self.tag_id}, name={self.name}, version={self.version}>'
@@ -1755,15 +1774,17 @@ def get_pypi_url(self) -> str:
17551774
def __comparable_tuple(self) -> _ComparableTuple:
17561775
return _ComparableTuple((
17571776
self.type, self.group, self.name, self.version,
1758-
self.mime_type, self.supplier, self.author, self.publisher,
1759-
self.description, self.scope, _ComparableTuple(self.hashes),
1760-
_ComparableTuple(self.licenses), self.copyright, self.cpe,
17611777
None if self.purl is None else _ComparablePackageURL(self.purl),
1762-
self.swid, self.pedigree,
1778+
self.swid, self.cpe, _ComparableTuple(self.swhids),
1779+
self.supplier, self.author, self.publisher,
1780+
self.description,
1781+
self.mime_type, self.scope, _ComparableTuple(self.hashes),
1782+
_ComparableTuple(self.licenses), self.copyright,
1783+
self.pedigree,
17631784
_ComparableTuple(self.external_references), _ComparableTuple(self.properties),
17641785
_ComparableTuple(self.components), self.evidence, self.release_notes, self.modified,
17651786
_ComparableTuple(self.authors), _ComparableTuple(self.omnibor_ids), self.manufacturer,
1766-
_ComparableTuple(self.swhids), self.crypto_properties, _ComparableTuple(self.tags),
1787+
self.crypto_properties, _ComparableTuple(self.tags),
17671788
))
17681789

17691790
def __eq__(self, other: object) -> bool:

cyclonedx/model/crypto.py

+63-44
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,19 @@ def certificate_extension(self) -> Optional[str]:
667667
def certificate_extension(self, certificate_extension: Optional[str]) -> None:
668668
self._certificate_extension = certificate_extension
669669

670+
def __comparable_tuple(self) -> _ComparableTuple:
671+
return _ComparableTuple((
672+
self.subject_name, self.issuer_name, self.not_valid_before, self.not_valid_after,
673+
self.certificate_format, self.certificate_extension
674+
))
675+
670676
def __eq__(self, other: object) -> bool:
671677
if isinstance(other, CertificateProperties):
672-
return hash(other) == hash(self)
678+
return self.__comparable_tuple() == other.__comparable_tuple()
673679
return False
674680

675681
def __hash__(self) -> int:
676-
# TODO
677-
return hash((self.subject_name, self.issuer_name, self.not_valid_before, self.not_valid_after,
678-
self.certificate_format, self.certificate_extension))
682+
return hash(self.__comparable_tuple())
679683

680684
def __repr__(self) -> str:
681685
return f'<CertificateProperties subject_name={self.subject_name}, certificate_format={self.certificate_format}>'
@@ -791,14 +795,18 @@ def algorithm_ref(self) -> Optional[BomRef]:
791795
def algorithm_ref(self, algorithm_ref: Optional[BomRef]) -> None:
792796
self._algorithm_ref = algorithm_ref
793797

798+
def __comparable_tuple(self) -> _ComparableTuple:
799+
return _ComparableTuple((
800+
self.mechanism, self.algorithm_ref
801+
))
802+
794803
def __eq__(self, other: object) -> bool:
795804
if isinstance(other, RelatedCryptoMaterialSecuredBy):
796-
return hash(other) == hash(self)
805+
return self.__comparable_tuple() == other.__comparable_tuple()
797806
return False
798807

799808
def __hash__(self) -> int:
800-
# TODO
801-
return hash((self.mechanism, self.algorithm_ref))
809+
return hash(self.__comparable_tuple())
802810

803811
def __repr__(self) -> str:
804812
return f'<RelatedCryptoMaterialSecuredBy mechanism={self.mechanism}, algorithm_ref={self.algorithm_ref}>'
@@ -1031,15 +1039,19 @@ def secured_by(self) -> Optional[RelatedCryptoMaterialSecuredBy]:
10311039
def secured_by(self, secured_by: Optional[RelatedCryptoMaterialSecuredBy]) -> None:
10321040
self._secured_by = secured_by
10331041

1042+
def __comparable_tuple(self) -> _ComparableTuple:
1043+
return _ComparableTuple((
1044+
self.type, self.id, self.state, self.algorithm_ref, self.creation_date, self.activation_date,
1045+
self.update_date, self.expiration_date, self.value, self.size, self.format, self.secured_by
1046+
))
1047+
10341048
def __eq__(self, other: object) -> bool:
10351049
if isinstance(other, RelatedCryptoMaterialProperties):
1036-
return hash(other) == hash(self)
1050+
return self.__comparable_tuple() == other.__comparable_tuple()
10371051
return False
10381052

10391053
def __hash__(self) -> int:
1040-
# TODO
1041-
return hash((self.type, self.id, self.state, self.algorithm_ref, self.creation_date, self.activation_date,
1042-
self.update_date, self.expiration_date, self.value, self.size, self.format, self.secured_by))
1054+
return hash(self.__comparable_tuple())
10431055

10441056
def __repr__(self) -> str:
10451057
return f'<RelatedCryptoMaterialProperties type={self.type}, id={self.id} state={self.state}>'
@@ -1140,23 +1152,23 @@ def identifiers(self) -> 'SortedSet[str]':
11401152
def identifiers(self, identifiers: Iterable[str]) -> None:
11411153
self._identifiers = SortedSet(identifiers)
11421154

1155+
def __comparable_tuple(self) -> _ComparableTuple:
1156+
return _ComparableTuple((
1157+
self.name, _ComparableTuple(self.algorithms), _ComparableTuple(self.identifiers)
1158+
))
1159+
11431160
def __eq__(self, other: object) -> bool:
11441161
if isinstance(other, ProtocolPropertiesCipherSuite):
1145-
return hash(other) == hash(self)
1162+
return self.__comparable_tuple() == other.__comparable_tuple()
11461163
return False
11471164

11481165
def __lt__(self, other: Any) -> bool:
11491166
if isinstance(other, ProtocolPropertiesCipherSuite):
1150-
return _ComparableTuple((
1151-
self.name, _ComparableTuple(self.algorithms), _ComparableTuple(self.identifiers)
1152-
)) < _ComparableTuple((
1153-
other.name, _ComparableTuple(other.algorithms), _ComparableTuple(other.identifiers)
1154-
))
1167+
return self.__comparable_tuple() < other.__comparable_tuple()
11551168
return NotImplemented
11561169

11571170
def __hash__(self) -> int:
1158-
# TODO
1159-
return hash((self.name, tuple(self.algorithms), tuple(self.identifiers)))
1171+
return hash(self.__comparable_tuple())
11601172

11611173
def __repr__(self) -> str:
11621174
return f'<ProtocolPropertiesCipherSuite name={self.name}>'
@@ -1282,14 +1294,23 @@ def auth(self) -> 'SortedSet[BomRef]':
12821294
def auth(self, auth: Iterable[BomRef]) -> None:
12831295
self._auth = SortedSet(auth)
12841296

1297+
def __comparable_tuple(self) -> _ComparableTuple:
1298+
return _ComparableTuple((
1299+
_ComparableTuple(self.encr),
1300+
_ComparableTuple(self.prf),
1301+
_ComparableTuple(self.integ),
1302+
_ComparableTuple(self.ke),
1303+
self.esn,
1304+
_ComparableTuple(self.auth)
1305+
))
1306+
12851307
def __eq__(self, other: object) -> bool:
12861308
if isinstance(other, Ikev2TransformTypes):
1287-
return hash(other) == hash(self)
1309+
return self.__comparable_tuple() == other.__comparable_tuple()
12881310
return False
12891311

12901312
def __hash__(self) -> int:
1291-
# TODO
1292-
return hash((tuple(self.encr), tuple(self.prf), tuple(self.integ), tuple(self.ke), self.esn, tuple(self.auth)))
1313+
return hash(self.__comparable_tuple())
12931314

12941315
def __repr__(self) -> str:
12951316
return f'<Ikev2TransformTypes esn={self.esn}>'
@@ -1382,14 +1403,18 @@ def ikev2_transform_types(self) -> Optional[Ikev2TransformTypes]:
13821403
def ikev2_transform_types(self, ikev2_transform_types: Optional[Ikev2TransformTypes]) -> None:
13831404
self._ikev2_transform_types = ikev2_transform_types
13841405

1406+
def __comparable_tuple(self) -> _ComparableTuple:
1407+
return _ComparableTuple((
1408+
self.type, self.version, _ComparableTuple(self.cipher_suites), self.ikev2_transform_types
1409+
))
1410+
13851411
def __eq__(self, other: object) -> bool:
13861412
if isinstance(other, ProtocolProperties):
1387-
return hash(other) == hash(self)
1413+
return self.__comparable_tuple() == other.__comparable_tuple()
13881414
return False
13891415

13901416
def __hash__(self) -> int:
1391-
# TODO
1392-
return hash((self.type, self.version, tuple(self.cipher_suites), self.ikev2_transform_types))
1417+
return hash(self.__comparable_tuple())
13931418

13941419
def __repr__(self) -> str:
13951420
return f'<ProtocolProperties type={self.type}, version={self.version}>'
@@ -1520,34 +1545,28 @@ def oid(self) -> Optional[str]:
15201545
def oid(self, oid: Optional[str]) -> None:
15211546
self._oid = oid
15221547

1548+
def __comparable_tuple(self) -> _ComparableTuple:
1549+
return _ComparableTuple((
1550+
self.asset_type,
1551+
self.algorithm_properties,
1552+
self.certificate_properties,
1553+
self.related_crypto_material_properties,
1554+
self.protocol_properties,
1555+
self.oid,
1556+
))
1557+
15231558
def __eq__(self, other: object) -> bool:
15241559
if isinstance(other, CryptoProperties):
1525-
return hash(other) == hash(self)
1560+
return self.__comparable_tuple() == other.__comparable_tuple()
15261561
return False
15271562

15281563
def __lt__(self, other: Any) -> bool:
15291564
if isinstance(other, CryptoProperties):
1530-
return _ComparableTuple((
1531-
self.asset_type,
1532-
self.algorithm_properties,
1533-
self.certificate_properties,
1534-
self.related_crypto_material_properties,
1535-
self.protocol_properties,
1536-
self.oid,
1537-
)) < _ComparableTuple((
1538-
other.asset_type,
1539-
other.algorithm_properties,
1540-
other.certificate_properties,
1541-
other.related_crypto_material_properties,
1542-
other.protocol_properties,
1543-
other.oid,
1544-
))
1565+
return self.__comparable_tuple() < other.__comparable_tuple()
15451566
return NotImplemented
15461567

15471568
def __hash__(self) -> int:
1548-
# TODO
1549-
return hash((self.asset_type, self.algorithm_properties, self.certificate_properties,
1550-
self.related_crypto_material_properties, self.protocol_properties, self.oid))
1569+
return hash(self.__comparable_tuple())
15511570

15521571
def __repr__(self) -> str:
15531572
return f'<CryptoProperties asset_type={self.asset_type}, oid={self.oid}>'

cyclonedx/model/dependency.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,23 @@ def dependencies(self, dependencies: Iterable['Dependency']) -> None:
8383
def dependencies_as_bom_refs(self) -> Set[BomRef]:
8484
return set(map(lambda d: d.ref, self.dependencies))
8585

86+
def __comparable_tuple(self) -> _ComparableTuple:
87+
return _ComparableTuple((
88+
self.ref, _ComparableTuple(self.dependencies)
89+
))
90+
8691
def __eq__(self, other: object) -> bool:
8792
if isinstance(other, Dependency):
88-
return hash(other) == hash(self)
93+
return self.__comparable_tuple() == other.__comparable_tuple()
8994
return False
9095

9196
def __lt__(self, other: Any) -> bool:
9297
if isinstance(other, Dependency):
93-
return _ComparableTuple((
94-
self.ref, _ComparableTuple(self.dependencies)
95-
)) < _ComparableTuple((
96-
other.ref, _ComparableTuple(other.dependencies)
97-
))
98+
return self.__comparable_tuple() < other.__comparable_tuple()
9899
return NotImplemented
99100

100101
def __hash__(self) -> int:
101-
# TODO
102-
return hash((self.ref, tuple(self.dependencies)))
102+
return hash(self.__comparable_tuple())
103103

104104
def __repr__(self) -> str:
105105
return f'<Dependency ref={self.ref!r}, targets={len(self.dependencies)}>'

0 commit comments

Comments
 (0)