polycvss
Rust library to parse and score CVSS vector strings.
Features:
- CVSS v2, CVSS v3, and CVSS v4 support.
- Version-agnostic parsing and scoring API.
- Memory efficient: Vectors are 8 bytes. Scores and severities are 1 byte.
- No dependencies by default except the standard library.
- Optional serde integration via the
serdebuild feature. - Extensive tests: Tested against thousands of vectors and scores from the NVD CVSS calculators.
Links:
Here is an example tool which parses the first command-line argument as a CVSS vector string, then prints the score and severity:
use ;
Here is the example tool output for a CVSS v2 vector string, a CVSS v3 vector string, and a CVSS v4 vector string:
# test with cvss v2 vector string
# test with cvss v3 vector string
# test with cvss v4 vector string
This example tool is included in the Git repository as
src/bin/cvss-score.rs.
Install
polycvss package page on crates.io
Run cargo add polycvss to add polycvss as a dependency to an
exiting Rust project:
Run cargo install polycvss to install the example cvss-score tool:
# install cvss-score in cargo bin dir (e.g. `~/.cargo/bin`)
Build
Run cargo build to create a debug build of the example tool in
target/debug:
Run cargo build --release to create a release build of the example
tool in target/release:
You can also build the example cvss-score tool in a container using
Podman or Docker like this:
To build a static binary of the example cvss-score tool in a container:
Documentation
polycvss API documentation on docs.rs
Run cargo doc to build the API documentation locally in
target/doc/polycvss/:
Run cargo doc --lib build the library documentation and exclude the
example tool documentation:
# remove generated docs
# (needed to clean up stale artifacts)
# generate library-only docs
Tests
Use cargo test to run the test suite:
; ; ; ; ;
Use cargo clippy to run the linter:
)
The test suite includes a large number of scored CVSS vector string test cases. The test cases were generated using cvss-calcs.
The generated test cases can be found in src/v3.rs,
src/v3.rs, and src/v4.rs.