Skip to content

Commit 42ca8e3

Browse files
committed
refactor: decode_cpe22
Signed-off-by: Meet Soni <[email protected]>
1 parent bae0d45 commit 42ca8e3

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

cve_bin_tool/sbom_manager/parse.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,6 @@ def parse_ext_ref(self, ext_ref) -> (str | None, str | None, str | None):
364364
decoded.get("cpe22Type", decoded.get("purl", (None, None, None))),
365365
)
366366

367-
def decode_cpe22(self, cpe22) -> (str | None, str | None, str | None):
368-
"""
369-
Decode a CPE 2.2 formatted string to extract vendor, product, and version information.
370-
371-
Args:
372-
- cpe22 (str): CPE 2.2 formatted string.
373-
374-
Returns:
375-
- Tuple[str | None, str | None, str | None]: A tuple containing the vendor, product, and version
376-
information extracted from the CPE 2.2 string, or None if the information is incomplete.
377-
378-
"""
379-
380-
# split on `:` only if it's not escaped
381-
cpe = re.split(r"(?<!\\):", cpe22)
382-
vendor, product, version = cpe[2], cpe[3], cpe[4]
383-
# Return available data, convert empty fields to None
384-
return [vendor or None, product or None, version or None]
385-
386367
def decode_purl(self, purl) -> (str | None, str | None, str | None):
387368
"""
388369
Decode a Package URL (purl) to extract version information.

cve_bin_tool/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,23 @@ def decode_cpe23(cpe23) -> list:
544544
vendor, product, version = cpe[3], cpe[4], cpe[5]
545545
# Return available data, convert empty fields to None
546546
return [vendor or None, product or None, version or None]
547+
548+
549+
def decode_cpe22(self, cpe22) -> list:
550+
"""
551+
Decode a CPE 2.2 formatted string to extract vendor, product, and version information.
552+
553+
Args:
554+
- cpe22 (str): CPE 2.2 formatted string.
555+
556+
Returns:
557+
- Tuple[str | None, str | None, str | None]: A tuple containing the vendor, product, and version
558+
information extracted from the CPE 2.2 string, or None if the information is incomplete.
559+
560+
"""
561+
562+
# split on `:` only if it's not escaped
563+
cpe = re.split(r"(?<!\\):", cpe22)
564+
vendor, product, version = cpe[2], cpe[3], cpe[4]
565+
# Return available data, convert empty fields to None
566+
return [vendor or None, product or None, version or None]

0 commit comments

Comments
 (0)