diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-01-31 14:36:08 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-01-31 14:36:08 -0500 |
commit | 566e511c9e5cbe6530dcd8212533f11f5d8ecb7a (patch) | |
tree | 51fca0ce6a97d4aac9d409dc8dad99e1ff4da40e | |
parent | a88d56a8287a3ed56c7f7d893682332a9ba0f015 (diff) | |
download | cvez-566e511c9e5cbe6530dcd8212533f11f5d8ecb7a.tar.bz2 cvez-566e511c9e5cbe6530dcd8212533f11f5d8ecb7a.zip |
mv internal/cvss/v3{,0}metric.go, add internal/cvss/v31metric.go
-rw-r--r-- | internal/cvss/cvss.go | 122 | ||||
-rw-r--r-- | internal/cvss/v30vector.go | 65 | ||||
-rw-r--r-- | internal/cvss/v31vector.go | 65 | ||||
-rw-r--r-- | internal/cvss/v3key.go | 5 |
4 files changed, 130 insertions, 127 deletions
diff --git a/internal/cvss/cvss.go b/internal/cvss/cvss.go index 6f1cafe..0e18656 100644 --- a/internal/cvss/cvss.go +++ b/internal/cvss/cvss.go @@ -1,128 +1,6 @@ // CVSS vector parser. package cvss -import ( - "strings" -) - -// CVSS v3.0 prefix -var v30Prefix = "CVSS:3.0/" - -// CVSS 3.0 vector. -type v30Vector []v3Metric - -// Convert vector to string -func (v v30Vector) String() string { - // convert to slice of metrics - metrics := []v3Metric(v) - - // build vector - r := make([]string, len(metrics)) - for i, m := range(metrics) { - r[i] = m.String() - } - - // build and return string - return v30Prefix + strings.Join(r, "/") -} - -// Return CVSS version. -func (v30Vector) Version() Version { - return V30 -} - -// Return metrics in this vector. -func (v v30Vector) Metrics() []Metric { - // build result - r := make([]Metric, len(v)) - for i, m := range(v) { - r[i] = m - } - - // return result - return r -} - -// create CVSS 3.0 vector from string -func newV30Vector(s string) (Vector, error) { - strs := strings.Split(s, "/") - r := make([]v3Metric, len(strs)) - - // walk metric strings - for i, ms := range(strs) { - // convert metric string to metric - m, err := getV3Metric(V30, ms) - if err != nil { - return nil, err - } - - // add to results - r[i] = m - } - - // build and return vector - return v30Vector(r), nil -} - -// CVSS v3.1 prefix -var v31Prefix = "CVSS:3.1/" - -// CVSS 3.1 vector. -type v31Vector []v3Metric - -// Convert vector to string -func (v v31Vector) String() string { - // convert to slice of metrics - metrics := []v3Metric(v) - - // build vector - r := make([]string, len(metrics)) - for i, m := range(metrics) { - r[i] = m.String() - } - - // build and return string - return v31Prefix + strings.Join(r, "/") -} - -// Return CVSS version. -func (v31Vector) Version() Version { - return V31 -} - -// Return metrics in this vector. -func (v v31Vector) Metrics() []Metric { - // build result - r := make([]Metric, len(v)) - for i, m := range(v) { - r[i] = m - } - - // return result - return r -} - -// create CVSS 3.1 vector from string -func newV31Vector(s string) (Vector, error) { - strs := strings.Split(s, "/") - r := make([]v3Metric, len(strs)) - - // walk metric strings - for i, ms := range(strs) { - // get metric from string - m, err := getV3Metric(V31, ms) - if err != nil { - return nil, err - } - - // add to results - r[i] = m - } - - // build and return vector - return v31Vector(r), nil -} - // Metric key. type Key interface { // Get full name. diff --git a/internal/cvss/v30vector.go b/internal/cvss/v30vector.go new file mode 100644 index 0000000..4154a2f --- /dev/null +++ b/internal/cvss/v30vector.go @@ -0,0 +1,65 @@ +// CVSS vector parser. +package cvss + +import ( + "strings" +) + +// CVSS v3.0 prefix +var v30Prefix = "CVSS:3.0/" + +// CVSS 3.0 vector. +type v30Vector []v3Metric + +// Convert vector to string +func (v v30Vector) String() string { + // convert to slice of metrics + metrics := []v3Metric(v) + + // build vector + r := make([]string, len(metrics)) + for i, m := range(metrics) { + r[i] = m.String() + } + + // build and return string + return v30Prefix + strings.Join(r, "/") +} + +// Return CVSS version. +func (v30Vector) Version() Version { + return V30 +} + +// Return metrics in this vector. +func (v v30Vector) Metrics() []Metric { + // build result + r := make([]Metric, len(v)) + for i, m := range(v) { + r[i] = m + } + + // return result + return r +} + +// create CVSS 3.0 vector from string +func newV30Vector(s string) (Vector, error) { + strs := strings.Split(s, "/") + r := make([]v3Metric, len(strs)) + + // walk metric strings + for i, ms := range(strs) { + // convert metric string to metric + m, err := getV3Metric(V30, ms) + if err != nil { + return nil, err + } + + // add to results + r[i] = m + } + + // build and return vector + return v30Vector(r), nil +} diff --git a/internal/cvss/v31vector.go b/internal/cvss/v31vector.go new file mode 100644 index 0000000..65536cf --- /dev/null +++ b/internal/cvss/v31vector.go @@ -0,0 +1,65 @@ +// CVSS vector parser. +package cvss + +import ( + "strings" +) + +// CVSS v3.1 prefix +var v31Prefix = "CVSS:3.1/" + +// CVSS 3.1 vector. +type v31Vector []v3Metric + +// Convert vector to string +func (v v31Vector) String() string { + // convert to slice of metrics + metrics := []v3Metric(v) + + // build vector + r := make([]string, len(metrics)) + for i, m := range(metrics) { + r[i] = m.String() + } + + // build and return string + return v31Prefix + strings.Join(r, "/") +} + +// Return CVSS version. +func (v31Vector) Version() Version { + return V31 +} + +// Return metrics in this vector. +func (v v31Vector) Metrics() []Metric { + // build result + r := make([]Metric, len(v)) + for i, m := range(v) { + r[i] = m + } + + // return result + return r +} + +// create CVSS 3.1 vector from string +func newV31Vector(s string) (Vector, error) { + strs := strings.Split(s, "/") + r := make([]v3Metric, len(strs)) + + // walk metric strings + for i, ms := range(strs) { + // get metric from string + m, err := getV3Metric(V31, ms) + if err != nil { + return nil, err + } + + // add to results + r[i] = m + } + + // build and return vector + return v31Vector(r), nil +} diff --git a/internal/cvss/v3key.go b/internal/cvss/v3key.go index 035620b..d54a086 100644 --- a/internal/cvss/v3key.go +++ b/internal/cvss/v3key.go @@ -1,11 +1,6 @@ package cvss -import ( - "strings" -) - //go:generate stringer -linecomment -type=v3Key -//go:generate stringer -linecomment -type=v3Metric // CVSS v3 metric key type v3Key byte |