Skip to content
/ cve Public

A collection of CVE (Common Vulnerabilities and Exposures) related utility methods. This package provides a series of utility functions for processing, verifying, extracting and manipulating CVE identifiers.

License

Notifications You must be signed in to change notification settings

scagogogo/cve

Repository files navigation

CVE Utils

Go Tests Documentation Go Reference Go Report Card License Version

🌐 Languages: English | 简体中文

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.

📖 Documentation

Complete API documentation and usage guides: https://scagogogo.github.io/cve/

Documentation includes:

📑 Table of Contents

✨ Features

  • ✅ 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

📦 Installation

go get github.com/scagogogo/cve

🚦 Quick Start

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]
}

📚 API Reference

Format & Validation

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

Extraction Methods

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

Comparison & Sorting

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

Filtering & Grouping

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

Generation & Construction

Function Description
GenerateCve(year int, seq int) string Generate CVE from year and sequence

💡 Usage Examples

Basic Validation

// Validate user input
func validateUserInput(input string) bool {
    return cve.ValidateCve(input)
}

Text Processing

// Extract CVEs from security bulletin
func extractFromBulletin(bulletin string) []string {
    return cve.ExtractCve(bulletin)
}

Data Cleaning

// Clean and sort CVE list
func cleanCveList(rawList []string) []string {
    unique := cve.RemoveDuplicateCves(rawList)
    return cve.SortCves(unique)
}

🏗️ Project Structure

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

📖 References

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A collection of CVE (Common Vulnerabilities and Exposures) related utility methods. This package provides a series of utility functions for processing, verifying, extracting and manipulating CVE identifiers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages