Skip to content

🛠️ Convenience Functions

This module exposes a set of package-level helper functions that simplify common CPE operations: parsing, validation, matching, conversion and filtering.

🚀 MustParse

go
func MustParse(cpeStr string) *CPE

Parses a CPE string and panics on failure. Suited for constants or test code.

ParameterTypeDescription
cpeStrstringThe CPE string
ReturnTypeDescription
#1*CPEThe parsed CPE object
go
cpe := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")

🔁 ParseOr

go
func ParseOr(cpeStr string, defaultCPE *CPE) *CPE

Parses a CPE string, returning defaultCPE on failure instead of an error.

ParameterTypeDescription
cpeStrstringThe CPE string
defaultCPE*CPEFallback value when parsing fails
ReturnTypeDescription
#1*CPEThe parsed result or the default
go
cpe := cpeskills.ParseOr("bad-string", cpeskills.MustParse("cpe:2.3:a:*:*:*:*:*:*:*:*:*"))

✅ IsCPE23String

go
func IsCPE23String(s string) bool

Reports whether the string conforms to the CPE 2.3 format.

ParameterTypeDescription
sstringThe string to test
ReturnTypeDescription
#1booltrue if it is a 2.3-formatted string
go
fmt.Println(cpeskills.IsCPE23String("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*"))

✅ IsCPE22String

go
func IsCPE22String(s string) bool

Reports whether the string conforms to the CPE 2.2 format.

ParameterTypeDescription
sstringThe string to test
ReturnTypeDescription
#1booltrue if it is a 2.2-formatted string
go
fmt.Println(cpeskills.IsCPE22String("cpe:/a:microsoft:windows:10"))

⚡ QuickMatch

go
func QuickMatch(cpeStr1, cpeStr2 string) (bool, error)

Quickly matches two CPE strings without manual parsing.

ParameterTypeDescription
cpeStr1stringThe first CPE string
cpeStr2stringThe second CPE string
ReturnTypeDescription
#1booltrue if they match
#2errorAn error if parsing fails
go
ok, err := cpeskills.QuickMatch(
    "cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*",
    "cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*",
)

🏷️ StringToPart

go
func StringToPart(s string) (*Part, error)

Converts a string into a Part value.

ParameterTypeDescription
sstringThe part string (e.g. a/o/h)
ReturnTypeDescription
#1*PartThe converted part
#2errorAn error for invalid values
go
part, err := cpeskills.StringToPart("a")

📝 FormatCPE

go
func FormatCPE(cpe *CPE, version string) (string, error)

Formats a CPE object according to the given CPE version ("2.2" or "2.3").

ParameterTypeDescription
cpe*CPEThe CPE object to format
versionstringTarget version
ReturnTypeDescription
#1stringThe formatted result
#2errorAn error for an invalid version
go
cpe := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
s, _ := cpeskills.FormatCPE(cpe, "2.2")

🧬 Clone

go
func Clone(cpe *CPE) *CPE

Deep-copies a CPE object.

ParameterTypeDescription
cpe*CPEThe CPE object to clone
ReturnTypeDescription
#1*CPEA new cloned object
go
cpe := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
clone := cpeskills.Clone(cpe)

🔁 CPEsToStrings

go
func CPEsToStrings(cpes []*CPE) []string

Converts a slice of CPE objects into a slice of URI strings (2.3 format).

ParameterTypeDescription
cpes[]*CPEThe CPE slice
ReturnTypeDescription
#1[]stringA slice of URI strings
go
cpes := []*CPE{cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")}
strs := cpeskills.CPEsToStrings(cpes)

🔁 StringsToCPEs

go
func StringsToCPEs(strs []string) []*CPE

Converts a slice of strings into a slice of CPE objects. Entries that fail to parse are skipped.

ParameterTypeDescription
strs[]stringThe CPE string slice
ReturnTypeDescription
#1[]*CPEThe parsed CPE slice
go
cpes := cpeskills.StringsToCPEs([]string{"cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*"})

🔎 FilterByPart

go
func FilterByPart(cpes []*CPE, part *Part) []*CPE

Filters a CPE list by part type.

ParameterTypeDescription
cpes[]*CPEThe list to filter
part*PartThe target part
ReturnTypeDescription
#1[]*CPEThe matching subset
go
part, _ := cpeskills.StringToPart("a")
apps := cpeskills.FilterByPart(cpes, part)

🔎 FilterByVendor

go
func FilterByVendor(cpes []*CPE, vendor string) []*CPE

Filters a CPE list by vendor.

ParameterTypeDescription
cpes[]*CPEThe list to filter
vendorstringThe target vendor
ReturnTypeDescription
#1[]*CPEThe matching subset
go
ms := cpeskills.FilterByVendor(cpes, "microsoft")

🔎 FilterByProduct

go
func FilterByProduct(cpes []*CPE, product string) []*CPE

Filters a CPE list by product name.

ParameterTypeDescription
cpes[]*CPEThe list to filter
productstringThe target product
ReturnTypeDescription
#1[]*CPEThe matching subset
go
wins := cpeskills.FilterByProduct(cpes, "windows")

🏷️ GetPartName

go
func GetPartName(shortName string) string

Converts a part short name (a/o/h) into its full name.

ParameterTypeDescription
shortNamestringThe short name
ReturnTypeDescription
#1stringThe full name
go
fmt.Println(cpeskills.GetPartName("a")) // application

🧭 Convenience Function Map

Released under the MIT License.