📦 CPE Core Type and Methods
CPE is the core type of this library, representing a Common Platform Enumeration object. It implements the CPE Name Matching specification, supports parsing and formatting of the 2.3 URI form, and provides set-relation comparisons (superset, subset, disjoint, equal).
Type: CPE
type CPE struct {
Cpe23 string `json:"cpe_23" bson:"cpe_23"`
Part Part `json:"part" bson:"part"`
Vendor Vendor `json:"vendor" bson:"vendor"`
ProductName Product `json:"product_name" bson:"product_name"`
Version Version `json:"version" bson:"version"`
Update Update `json:"update" bson:"update"`
Edition Edition `json:"edition" bson:"edition"`
Language Language `json:"language" bson:"language"`
SoftwareEdition string `json:"software_edition" bson:"software_edition"`
TargetSoftware string `json:"target_software" bson:"target_software"`
TargetHardware string `json:"target_hardware" bson:"target_hardware"`
Other string `json:"other" bson:"other"`
Cve string `json:"cve" bson:"cve"`
Url string `json:"url" bson:"url"`
}The fields of the CPE struct correspond to the attributes defined by the CPE 2.3 specification, plus two extension fields: Cve (associated vulnerability identifier) and Url (information source).
🔍 Match
func (x *CPE) Match(other *CPE) boolReports whether the current CPE matches another CPE, following the CPE Name Matching specification. The matching rules account for the special semantics of the wildcard * and the not-applicable marker -: identical URIs match directly; Part must match exactly; for the remaining attributes, either side being * matches, both being - matches, and otherwise exact equality is required.
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The target CPE to compare against |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if they match, false otherwise |
package main
import (
"fmt"
"github.com/scagogogo/cpe-skills"
)
func main() {
windowsCPE, _ := cpeskills.ParseCpe23("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
pattern, _ := cpeskills.ParseCpe23("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
if pattern.Match(windowsCPE) {
fmt.Println("matched")
}
}⚙️ GetURI
func (c *CPE) GetURI() stringReturns the 2.3-formatted URI string of this CPE object.
| Return | Type | Description |
|---|---|---|
| #1 | string | The CPE 2.3 URI string |
cpe, _ := cpeskills.ParseCpe23("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(cpe.GetURI())🧩 FormatURI
func FormatURI(cpe *CPE) stringFormats a CPE object into a 2.3 URI string; the package-level counterpart of GetURI.
| Parameter | Type | Description |
|---|---|---|
cpe | *CPE | The CPE object to format |
| Return | Type | Description |
|---|---|---|
| #1 | string | The CPE 2.3 URI string |
cpe := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(cpeskills.FormatURI(cpe))🎯 MatchCPE
func MatchCPE(criteria *CPE, target *CPE, options *MatchOptions) boolReports whether criteria matches target according to the optional matching options. Passing nil for options uses the default rules.
| Parameter | Type | Description |
|---|---|---|
criteria | *CPE | The matching pattern |
target | *CPE | The target CPE being matched |
options | *MatchOptions | Matching options, nil for defaults |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if matched, false otherwise |
criteria := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
target := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
if cpeskills.MatchCPE(criteria, target, nil) {
fmt.Println("target matches criteria")
}📊 CompareTo
func (x *CPE) CompareTo(other *CPE) RelationCompares the current CPE with another and returns the set relation between them.
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The other CPE to compare with |
| Return | Type | Description |
|---|---|---|
| #1 | Relation | The relation (equal, superset, subset, disjoint, etc.) |
a := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
b := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(a.CompareTo(b))⬆️ IsSupersetOf
func (x *CPE) IsSupersetOf(other *CPE) boolReports whether the current CPE is a superset of another.
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The other CPE to compare with |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is a superset, false otherwise |
a := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
b := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(a.IsSupersetOf(b))⬇️ IsSubsetOf
func (x *CPE) IsSubsetOf(other *CPE) boolReports whether the current CPE is a subset of another.
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The other CPE to compare with |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if it is a subset, false otherwise |
a := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
b := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
fmt.Println(a.IsSubsetOf(b))🚫 IsDisjointWith
func (x *CPE) IsDisjointWith(other *CPE) boolReports whether the current CPE is disjoint with another (no overlap at all).
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The other CPE to compare with |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if disjoint, false otherwise |
a := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:*:*:*:*:*:*:*:*")
b := cpeskills.MustParse("cpe:2.3:a:adobe:reader:*:*:*:*:*:*:*:*")
fmt.Println(a.IsDisjointWith(b))🟰 IsEqualTo
func (x *CPE) IsEqualTo(other *CPE) boolReports whether the current CPE is equal to another.
| Parameter | Type | Description |
|---|---|---|
other | *CPE | The other CPE to compare with |
| Return | Type | Description |
|---|---|---|
| #1 | bool | true if equal, false otherwise |
a := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
b := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(a.IsEqualTo(b))