diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-01 23:53:56 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-01 23:53:56 -0500 |
commit | ce92ab3114dc8f5d9654dbfeecefb44049ea1a0c (patch) | |
tree | 3bc889b16aff9f8af9eed2572bebc8e70cb2b0d0 /internal/cvss/vector.go | |
parent | 639ebc03c5dd60e104f255d0b0f2fb45ec319799 (diff) | |
download | cvez-ce92ab3114dc8f5d9654dbfeecefb44049ea1a0c.tar.bz2 cvez-ce92ab3114dc8f5d9654dbfeecefb44049ea1a0c.zip |
internal/cvss: add isVectorString tests
Diffstat (limited to 'internal/cvss/vector.go')
-rw-r--r-- | internal/cvss/vector.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/cvss/vector.go b/internal/cvss/vector.go new file mode 100644 index 0000000..3e465c5 --- /dev/null +++ b/internal/cvss/vector.go @@ -0,0 +1,36 @@ +package cvss + +import ( + "fmt" +) + +// CVSS metric vector. +type Vector interface { + // Get CVSS version. + Version() Version + + // Get CVSS vector string. + String() string + + // Return metrics in this vector. + Metrics() []Metric + + // Unmarshal vector from JSON. + // UnmarshalJSON(b []byte) error +} + +// Create new CVSS vector from vector string. +func NewVector(s string) (Vector, error) { + if isV31VectorString(s) { + // create CVSS v3.1 vector. + return newV31Vector(s) + } else if isV30VectorString(s) { + // create CVSS v3.0 vector. + return newV30Vector(s) + } else if isV2VectorString(s) { + // create CVSS v2 vector. + return newV2Vector(s) + } else { + return nil, fmt.Errorf("invalid CVSS vector: %s", s) + } +} |