From 566e511c9e5cbe6530dcd8212533f11f5d8ecb7a Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 31 Jan 2022 14:36:08 -0500 Subject: mv internal/cvss/v3{,0}metric.go, add internal/cvss/v31metric.go --- internal/cvss/v31vector.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 internal/cvss/v31vector.go (limited to 'internal/cvss/v31vector.go') 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 +} -- cgit v1.2.3