Add reproducible evaluation and provenance research
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from enum import IntEnum
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -58,10 +59,21 @@ class Finding:
|
||||
remediation: str | None = None
|
||||
tags: tuple[str, ...] = ()
|
||||
|
||||
def fingerprint(self) -> str:
|
||||
material = "\0".join((
|
||||
self.rule_id,
|
||||
self.artifact_path,
|
||||
str(self.line or 0),
|
||||
str(self.column or 0),
|
||||
self.message,
|
||||
)).encode("utf-8")
|
||||
return hashlib.sha256(material).hexdigest()
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
result = asdict(self)
|
||||
result["severity"] = self.severity.label()
|
||||
result["tags"] = list(self.tags)
|
||||
result["fingerprint"] = self.fingerprint()
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user