Skip to content

🔍 CPE 2.2 Parser

This module provides parsing and formatting for the CPE 2.2 form (the legacy URI prefixed with cpe:).

Constant

go
const CPE22Header = "cpe"

CPE22Header is the fixed prefix of a CPE 2.2 URI; every well-formed 2.2 string begins with cpe:.

📥 ParseCpe22

go
func ParseCpe22(cpe22 string) (*CPE, error)

Parses a CPE 2.2-formatted string into a CPE object. The string should start with the cpe: prefix and carry attributes such as part:vendor:product:version.

ParameterTypeDescription
cpe22stringThe CPE 2.2 string to parse
ReturnTypeDescription
#1*CPEThe parsed CPE object
#2errorAn error if parsing fails
go
package main

import (
    "fmt"
    "github.com/scagogogo/cpe-skills"
)

func main() {
    cpe, err := cpeskills.ParseCpe22("cpe:/a:microsoft:windows:10")
    if err != nil {
        panic(err)
    }
    fmt.Println(cpe.GetURI())
}

📤 FormatCpe22

go
func FormatCpe22(cpe *CPE) string

Formats a CPE object into a CPE 2.2 URI string.

ParameterTypeDescription
cpe*CPEThe CPE object to format
ReturnTypeDescription
#1stringThe CPE 2.2 URI string
go
cpe := cpeskills.MustParse("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
fmt.Println(cpeskills.FormatCpe22(cpe))

🔄 Parse Flow

Released under the MIT License.