Skip to content

Commit

Permalink
fix(CVSS2, CVSS3): correct __eq__ methods for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
fqlenos committed Sep 12, 2024
1 parent 8347d94 commit 45bf9e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions cvss/cvss2.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,6 @@ def rh_vector(self):
"""
return str(self.scores()[0]) + "/" + self.clean_vector()

def __eq__(self, o):
if isinstance(o, CVSS2):
return self.clean_vector().__eq__(o.clean_vector())
return NotImplemented

def __hash__(self):
return hash(self.clean_vector())

def as_json(self, sort=False, minimal=False):
"""
Returns a dictionary formatted with attribute names and values defined by the official
Expand Down Expand Up @@ -381,3 +373,11 @@ def add_metric_to_data(metric):
data = OrderedDict(sorted(data.items()))

return data

def __hash__(self) -> int:
return hash(self.clean_vector())

def __eq__(self, o) -> bool:
if isinstance(o, CVSS2):
return self.clean_vector() == o.clean_vector()
return False
16 changes: 8 additions & 8 deletions cvss/cvss3.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,6 @@ def rh_vector(self):
"""
return str(self.scores()[0]) + "/" + self.clean_vector()

def __eq__(self, o):
if isinstance(o, CVSS3):
return self.clean_vector().__eq__(o.clean_vector())
return NotImplemented

def __hash__(self):
return hash(self.clean_vector())

def as_json(self, sort=False, minimal=False):
"""
Returns a dictionary formatted with attribute names and values defined by the official
Expand Down Expand Up @@ -508,3 +500,11 @@ def add_metric_to_data(metric):
if sort:
data = OrderedDict(sorted(data.items()))
return data

def __hash__(self) -> int:
return hash(self.clean_vector())

def __eq__(self, o) -> bool:
if isinstance(o, CVSS3):
return self.clean_vector() == o.clean_vector()
return False

0 comments on commit 45bf9e0

Please sign in to comment.