From ab7a176d60bf7073933451606120d039c3165da2 Mon Sep 17 00:00:00 2001 From: Matthew Kincaid Date: Thu, 29 Feb 2024 06:58:35 -0500 Subject: [PATCH] feat: Made Remark enumeration human readable in reports --- cve_bin_tool/util.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cve_bin_tool/util.py b/cve_bin_tool/util.py index f2c97b2af1..358076823e 100644 --- a/cve_bin_tool/util.py +++ b/cve_bin_tool/util.py @@ -81,14 +81,14 @@ class Remarks(OrderedEnum): Each member of the enumeration represents a specific remark with a unique value. """ - NewFound = 1, "1", "NewFound", "n", "N" - Unexplored = 2, "2", "Unexplored", "u", "U", "" - Confirmed = 3, "3", "Confirmed", "c", "C" - Mitigated = 4, "4", "Mitigated", "m", "M" - FalsePositive = 5, "5", "FalsePositive", "f", "F" - NotAffected = 6, "6", "NotAffected", "i", "I" - - def __new__(cls, value: int, *aliases: str) -> Remarks: + NewFound = 1, "New", "1", "NewFound", "n", "N" + Unexplored = 2, "Unexplored", "2", "Unexplored", "u", "U", "" + Confirmed = 3, "Confirmed", "3", "Confirmed", "c", "C" + Mitigated = 4, "Mitigated", "4", "Mitigated", "m", "M" + FalsePositive = 5, "False Positive", "5", "FalsePositive", "f", "F" + NotAffected = 6, "Not Affected", "6", "NotAffected", "i", "I" + + def __new__(cls, value: int, string: str, *aliases: str) -> Remarks: """ Return a new instance of the Remarks enumeration. """ @@ -96,8 +96,17 @@ def __new__(cls, value: int, *aliases: str) -> Remarks: obj._value_ = value for alias in aliases: cls._value2member_map_[alias] = obj + string_map = getattr(cls, "string_map", {}) + string_map[value] = string + cls.string_map = string_map return obj + def __str__(self): + """ + Returns a human-readable string of the enumeration value + """ + return self.string_map[self.value] + class CVE(NamedTuple): """