pub struct Vector(/* private fields */);Expand description
CVSS v4 vector.
Notes:
- Represented internally as a
u64. See Internal Representation below. - When iterating the metrics in a
Vectoror converting aVectorto a string, the metrics are sorted in the order specified in Table 23 of Section 7 of the CVSS v4.0 specification; the sort order of metrics within the source vector string is not preserved. See Examples below. - Optional metrics with a value of
Not Defined (X)are skipped when iterating the metrics in aVectorand when converting aVectorto a string. See Examples below.
§Examples
// CVSS v4.0 vector string
let s = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H";
// parse string as Vector
let v: Vector = s.parse()?;Iterate over vector metrics:
// parse vector string
let v: Vector = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H".parse()?;
// iterate over and print each metric
for m in v {
println!("metric: {m}");
}Get metric from vector:
// parse vector string
let v: Vector = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H".parse()?;
// get metric
let metric = v.get(Name::AttackVector);
// check result
assert_eq!(metric, Metric::AttackVector(AttackVector::Network));Show that the order of metrics within a vector string is not
preserved when parsing a vector string and then converting the
Vector back to a string:
// vector string with first two metrics (AV and AC) swapped
let s = "CVSS:4.0/AC:L/AV:N/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H";
// expected result after parsing vector string above and converting
// the parsed vector back to a vector string
let exp = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H";
// parse vector string, then convert parsed vector back to vector string
let got = s.parse::<Vector>()?.to_string();
// check result
assert_eq!(got, exp);Show that optional metrics with a value of Not Defined (X) are
not preserved when parsing a vector string and then converting the
Vector back to a string:
// vector string which contains an optional metric (MAV) with a
// value of `Not Defined (X)`
let s = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/MAV:X";
// expected result after parsing vector string above and converting
// the parsed vector back to a vector string
let exp = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H";
// parse vector string, then convert parsed vector back to vector string
let got = s.parse::<Vector>()?.to_string();
// check result
assert_eq!(got, exp);Verify that a vector is the same size as a u64:
assert_eq!(size_of::<Vector>(), size_of::<u64>());§Internal Representation
A CVSS v4 Vector is represented internally as a bit
field within a u64. Metric values are stored in
the lower 59 bits (bits 0..59) and the CVSS version is stored in
the in the upper 4 bits (bits 60..64):
| Bit Range | Description |
|---|---|
0..28 | Metrics with 2 or 4 possible values. |
28..59 | Metrics with 3 or 5 possible values. |
59..60 | 1 unused bit. |
60..64 | CVSS version (4.0). |
- Metrics with 2 or 4 possible values are stored in the lower 28
bits (bits
0..28). The value of metrics with 2 possible values are represented as 1 bit. The value of metrics with 4 possible values are represented as 2 bits. - Metrics with 3 or 5 possible values are encoded in the next 30
bits (bits
28..59). The value of these metrics are encoded as multiples of a base consisting of powers of 3 and 5.
Implementations§
Source§impl Vector
impl Vector
Sourcepub fn get(self, name: Name) -> Metric
pub fn get(self, name: Name) -> Metric
Get Metric from Vector by Name.
§Examples
Get metric from vector:
// parse vector string
let v: Vector = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H".parse()?;
// get metric
let metric = v.get(Name::AttackVector);
// check result
assert_eq!(metric, Metric::AttackVector(AttackVector::Network));Get optional metric from vector:
// parse vector string
let v: Vector = "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H".parse()?;
// get metric
let metric = v.get(Name::ModifiedAttackVector);
// check result
assert_eq!(metric, Metric::ModifiedAttackVector(ModifiedAttackVector::NotDefined));Trait Implementations§
Source§impl From<Vector> for MacroVector
impl From<Vector> for MacroVector
Source§fn from(vec: Vector) -> MacroVector
fn from(vec: Vector) -> MacroVector
Converts to this type from the input type.
Source§impl From<Vector> for Nomenclature
impl From<Vector> for Nomenclature
Source§fn from(vec: Vector) -> Nomenclature
fn from(vec: Vector) -> Nomenclature
Converts to this type from the input type.
Source§impl IntoIterator for Vector
impl IntoIterator for Vector
impl Copy for Vector
impl Eq for Vector
impl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more