@@ -3010,6 +3010,13 @@ class AdvisoryV2(models.Model):
30103010 help_text = "Related advisories that are used to calculate the severity of this advisory." ,
30113011 )
30123012
3013+ advisory_content_hash = models .CharField (
3014+ max_length = 64 ,
3015+ blank = True ,
3016+ null = True ,
3017+ help_text = "A unique hash computed from the content of the advisory used to identify advisories with the same content." ,
3018+ )
3019+
30133020 @property
30143021 def risk_score (self ):
30153022 """
@@ -3078,35 +3085,6 @@ def get_aliases(self):
30783085 """
30793086 return self .aliases .all ()
30803087
3081- def compute_advisory_content (self ):
3082- """
3083- Compute a unique content hash for an advisory by normalizing its data and hashing it.
3084-
3085- :param advisory: An Advisory object
3086- :return: SHA-256 hash digest as content hash
3087- """
3088- normalized_data = {
3089- "summary" : normalize_text (self .summary ),
3090- "impacted_packages" : sorted (
3091- [impact .to_dict () for impact in self .impacted_packages .all ()],
3092- key = lambda x : json .dumps (x , sort_keys = True ),
3093- ),
3094- "patches" : sorted (
3095- [patch .to_patch_data ().to_dict () for patch in self .patches .all ()],
3096- key = lambda x : json .dumps (x , sort_keys = True ),
3097- ),
3098- "severities" : sorted (
3099- [sev .to_vulnerability_severity_data ().to_dict () for sev in self .severities .all ()],
3100- key = lambda x : (x .get ("system" ), x .get ("value" )),
3101- ),
3102- "weaknesses" : normalize_list ([weakness .cwe_id for weakness in self .weaknesses .all ()]),
3103- }
3104-
3105- normalized_json = json .dumps (normalized_data , separators = ("," , ":" ), sort_keys = True )
3106- content_hash = hashlib .sha256 (normalized_json .encode ("utf-8" )).hexdigest ()
3107-
3108- return content_hash
3109-
31103088 alias = get_aliases
31113089
31123090
0 commit comments