diff --git a/cyclonedx/model/contact.py b/cyclonedx/model/contact.py index 3266bd92..cea865e7 100644 --- a/cyclonedx/model/contact.py +++ b/cyclonedx/model/contact.py @@ -254,23 +254,23 @@ def phone(self) -> Optional[str]: def phone(self, phone: Optional[str]) -> None: self._phone = phone + def __comparable_tuple(self) -> _ComparableTuple: + return _ComparableTuple(( + self.name, self.email, self.phone + )) + def __eq__(self, other: object) -> bool: if isinstance(other, OrganizationalContact): - return hash(other) == hash(self) + return self.__comparable_tuple() == other.__comparable_tuple() return False def __lt__(self, other: Any) -> bool: if isinstance(other, OrganizationalContact): - return _ComparableTuple(( - self.name, self.email, self.phone - )) < _ComparableTuple(( - other.name, other.email, other.phone - )) + return self.__comparable_tuple() < other.__comparable_tuple() return NotImplemented def __hash__(self) -> int: - # TODO - return hash((self.name, self.phone, self.email)) + return hash(self.__comparable_tuple()) def __repr__(self) -> str: return f'' @@ -364,19 +364,23 @@ def contacts(self) -> 'SortedSet[OrganizationalContact]': def contacts(self, contacts: Iterable[OrganizationalContact]) -> None: self._contacts = SortedSet(contacts) + def __comparable_tuple(self) -> _ComparableTuple: + return _ComparableTuple(( + self.name, _ComparableTuple(self.urls), _ComparableTuple(self.contacts) + )) + def __eq__(self, other: object) -> bool: if isinstance(other, OrganizationalEntity): - return hash(other) == hash(self) + return self.__comparable_tuple() == other.__comparable_tuple() return False def __lt__(self, other: Any) -> bool: if isinstance(other, OrganizationalEntity): - return hash(self) < hash(other) + return self.__comparable_tuple() < other.__comparable_tuple() return NotImplemented def __hash__(self) -> int: - # TODO - return hash((self.name, tuple(self.urls), tuple(self.contacts))) + return hash(self.__comparable_tuple()) def __repr__(self) -> str: return f'' diff --git a/cyclonedx/model/crypto.py b/cyclonedx/model/crypto.py index 3864324c..765e840b 100644 --- a/cyclonedx/model/crypto.py +++ b/cyclonedx/model/crypto.py @@ -494,16 +494,20 @@ def nist_quantum_security_level(self, nist_quantum_security_level: Optional[int] ) self._nist_quantum_security_level = nist_quantum_security_level + def __comparable_tuple(self) -> _ComparableTuple: + return _ComparableTuple(( + self.primitive, self._parameter_set_identifier, self.curve, self.execution_environment, + self.implementation_platform, _ComparableTuple(self.certification_levels), self.mode, self.padding, + _ComparableTuple(self.crypto_functions), self.classical_security_level, self.nist_quantum_security_level, + )) + def __eq__(self, other: object) -> bool: if isinstance(other, AlgorithmProperties): - return hash(other) == hash(self) + return self.__comparable_tuple() == other.__comparable_tuple() return False def __hash__(self) -> int: - # TODO - return hash((self.primitive, self._parameter_set_identifier, self.curve, self.execution_environment, - self.implementation_platform, tuple(self.certification_levels), self.mode, self.padding, - tuple(self.crypto_functions), self.classical_security_level, self.nist_quantum_security_level,)) + return hash(self.__comparable_tuple()) def __repr__(self) -> str: return f'' diff --git a/cyclonedx/model/vulnerability.py b/cyclonedx/model/vulnerability.py index fc6d1ce1..7805b53d 100644 --- a/cyclonedx/model/vulnerability.py +++ b/cyclonedx/model/vulnerability.py @@ -461,22 +461,23 @@ def url(self) -> Optional[XsUri]: def url(self, url: Optional[XsUri]) -> None: self._url = url + def __comparable_tuple(self) -> _ComparableTuple: + return _ComparableTuple(( + self.name, self.url + )) + def __eq__(self, other: object) -> bool: if isinstance(other, VulnerabilitySource): - return hash(other) == hash(self) + return self.__comparable_tuple() == other.__comparable_tuple() return False def __lt__(self, other: Any) -> bool: if isinstance(other, VulnerabilitySource): - return _ComparableTuple(( - self.name, self.url - )) < _ComparableTuple(( - other.name, other.url - )) + return self.__comparable_tuple() < other.__comparable_tuple() return NotImplemented def __hash__(self) -> int: - return hash((self.name, self.url)) + return hash(self.__comparable_tuple()) def __repr__(self) -> str: return f''