#cwe #security #strongly-typed #access #enumeration #tiny #object

no-std cwenum

A tiny crate to access a strongly typed common weakness enumeration (cwe) object

2 stable releases

new 1.0.1 Feb 21, 2025
1.0.0 Jan 18, 2025

#55 in No standard library

Download history 118/week @ 2025-01-17 39/week @ 2025-01-24 26/week @ 2025-01-31 7/week @ 2025-02-07

190 downloads per month

MIT license

685KB
8K SLoC

cwenum

cwenum crate logo

A tiny crate to access a strongly typed common weakness enumeration (cwe) object. Everything is ready to use at compile time, no further setup or network calls at runtime are required.

Usage

Include something along the lines of

cwenum = { version = "1.0", default-features = false, features = ["std"] }

in your Cargo.toml. You now have access to the cwenum::Cwe enum.

Available feature flags:

  • std: Link against the standard library. Enabled by default. Omit this and compile without default features if you are building no_std applications.
  • iterable: Offers Cwe::iterator(), which can be used to loop through all CWEs.
  • str: Offers some conversion functionality to and from &str. Roughly doubles artifact size to about 1.5 MB.
  • serde: Implements Deserialize and Serialize for Cwe. Requires the std and str flags.

Example

use cwenum::Cwe;

let cwe = Cwe::Cwe89;
// The enum is cloneable...
let _cwe_clone = cwe.clone();
// ...copyable...
let _cwe_copy = cwe;
// ...comparable...
assert_eq!(cwe, Cwe::Cwe89);
// ...and hashable.
let mut map = std::collections::HashMap::new();
map.insert(cwe, "CWE-89");

// If the crate is compiled with the `str` feature, it offers more functionality:
println!("{}", cwe.id());
println!("{}", cwe.name());
println!("{}", cwe.description());
let cwe_79: Cwe = "CWE-79".try_into().unwrap();
assert_eq!(cwe_79, Cwe::Cwe79);
// If the `std` feature flag is left active, the conversion is not case sensitive
let cwe_80: Cwe = "cwe-80".try_into().unwrap();
assert_eq!(cwe_80, Cwe::Cwe80);

// If the crate is compiled with the `iterable` feature, the enum offers an iterator:
for cwe in Cwe::iterator().take(3) {
    println!("{}", cwe.id())
}

License

This software is distributed under the MIT license. In a nutshell this means that all code is made public, and you are free to use it without any charge.

Dependencies