Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CVSS2, CVSS3, CVSS4): implement and correct __eq__ methods #62

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
return hash(self.clean_vector())

def __eq__(self, o):
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):
return hash(self.clean_vector())

def __eq__(self, o):
if isinstance(o, CVSS3):
return self.clean_vector() == o.clean_vector()
return False
11 changes: 8 additions & 3 deletions cvss/cvss4.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,6 @@ def compute_base_score(self):

self.base_score = round_away_from_zero(value)

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

def clean_vector(self, output_prefix=True):
"""
Returns vector without optional metrics marked as X and in preferred order.
Expand Down Expand Up @@ -670,3 +667,11 @@ def add_metric_to_data(metric):
if sort:
data = OrderedDict(sorted(data.items()))
return data

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

def __eq__(self, o):
if isinstance(o, CVSS4):
return self.clean_vector() == o.clean_vector()
return False
Loading