A comprehensive collection of utility functions for handling CVE (Common Vulnerabilities and Exposures) identifiers. This package provides a series of practical functions for processing, validating, extracting, and manipulating CVE identifiers.
Complete API documentation and usage guides: https://scagogogo.github.io/cve/
Documentation includes:
- ✅ CVE format validation and standardization
- ✅ Extract CVE identifiers from text
- ✅ Extract and compare CVE years and sequence numbers
- ✅ Sort, filter, and group CVEs
- ✅ Generate standard format CVE identifiers
- ✅ Deduplication and validation tools
go get github.com/scagogogo/cve
package main
import (
"fmt"
"github.com/scagogogo/cve"
)
func main() {
// Format CVE
formatted := cve.Format("cve-2022-12345")
fmt.Println(formatted) // Output: CVE-2022-12345
// Validate CVE
isValid := cve.ValidateCve("CVE-2022-12345")
fmt.Println(isValid) // Output: true
// Extract CVE from text
text := "System affected by CVE-2021-44228 and CVE-2022-12345"
cves := cve.ExtractCve(text)
fmt.Println(cves) // Output: [CVE-2021-44228 CVE-2022-12345]
}
Function | Description |
---|---|
Format(cve string) string |
Convert CVE to standard uppercase format |
IsCve(text string) bool |
Check if string is a valid CVE format |
IsContainsCve(text string) bool |
Check if string contains CVE |
ValidateCve(cve string) bool |
Comprehensive validation of CVE identifier |
Function | Description |
---|---|
ExtractCve(text string) []string |
Extract all CVE identifiers from text |
ExtractFirstCve(text string) string |
Extract the first CVE identifier |
ExtractLastCve(text string) string |
Extract the last CVE identifier |
Split(cve string) (year string, seq string) |
Split CVE into year and sequence |
Function | Description |
---|---|
CompareCves(cveA, cveB string) int |
Comprehensive comparison of two CVEs |
SortCves(cveSlice []string) []string |
Sort CVE slice |
CompareByYear(cveA, cveB string) int |
Compare two CVEs by year |
Function | Description |
---|---|
FilterCvesByYear(cveSlice []string, year int) []string |
Filter CVEs by specific year |
GroupByYear(cveSlice []string) map[string][]string |
Group CVEs by year |
RemoveDuplicateCves(cveSlice []string) []string |
Remove duplicate CVEs |
Function | Description |
---|---|
GenerateCve(year int, seq int) string |
Generate CVE from year and sequence |
// Validate user input
func validateUserInput(input string) bool {
return cve.ValidateCve(input)
}
// Extract CVEs from security bulletin
func extractFromBulletin(bulletin string) []string {
return cve.ExtractCve(bulletin)
}
// Clean and sort CVE list
func cleanCveList(rawList []string) []string {
unique := cve.RemoveDuplicateCves(rawList)
return cve.SortCves(unique)
}
cve/
├── cve.go # Main functionality
├── cve_test.go # Unit tests
├── README.md # English documentation
├── README.zh.md # Chinese documentation
├── LICENSE # License file
└── docs/ # Documentation website
├── index.md # English homepage
├── zh/ # Chinese documentation
├── api/ # API documentation
├── guide/ # Usage guides
└── examples/ # Usage examples
This project is licensed under the MIT License - see the LICENSE file for details.