API Reference
The CPE library provides a comprehensive set of APIs for working with Common Platform Enumeration (CPE) data. This section covers all public types, functions, and interfaces available in the library.
Overview
The library is organized into several key areas:
- Core Types - Basic data structures and type definitions
- Parsing - Functions for parsing CPE strings
- Matching - CPE matching and comparison functions
- Storage - Data persistence interfaces and implementations
- Dictionary - CPE dictionary management
- NVD Integration - National Vulnerability Database integration
- WFN - Well-Formed Name format support
- Validation - CPE validation functions
- Sets - CPE set operations
- Errors - Error types and handling
Quick Reference
Core Functions
go
// Parse CPE strings
func ParseCpe23(cpe23 string) (*CPE, error)
func ParseCpe22(cpe22 string) (*CPE, error)
// Format CPE strings
func FormatCpe23(cpe *CPE) string
func FormatCpe22(cpe *CPE) string
// Match CPEs
func (c *CPE) Match(other *CPE) bool
func MatchCPE(cpe1, cpe2 *CPE, options *MatchOptions) bool
func AdvancedMatchCPE(criteria, target *CPE, options *AdvancedMatchOptions) bool
// Storage operations
func NewFileStorage(baseDir string, enableCache bool) (*FileStorage, error)
func NewMemoryStorage() *MemoryStorage
Core Types
go
type CPE struct {
Cpe23 string
Part Part
Vendor Vendor
ProductName Product
Version Version
Update Update
Edition Edition
Language Language
SoftwareEdition string
TargetSoftware string
TargetHardware string
Other string
Cve string
Url string
}
type Part struct {
ShortName string
LongName string
Description string
}
Installation
bash
go get github.com/scagogogo/cpe
Import
go
import "github.com/scagogogo/cpe"
Basic Usage
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/cpe"
)
func main() {
// Parse a CPE string
cpeObj, err := cpe.ParseCpe23("cpe:2.3:a:microsoft:windows:10:*:*:*:*:*:*:*")
if err != nil {
log.Fatal(err)
}
// Access CPE components
fmt.Printf("Part: %s\n", cpeObj.Part.LongName)
fmt.Printf("Vendor: %s\n", cpeObj.Vendor)
fmt.Printf("Product: %s\n", cpeObj.ProductName)
fmt.Printf("Version: %s\n", cpeObj.Version)
// Match with another CPE
pattern, _ := cpe.ParseCpe23("cpe:2.3:a:microsoft:*:*:*:*:*:*:*:*:*")
if pattern.Match(cpeObj) {
fmt.Println("CPE matches the pattern")
}
}
Next Steps
- Explore the Core Types to understand the data structures
- Learn about Parsing CPE strings
- Discover Matching capabilities
- Check out practical Examples