blob: efa24444d4f559c6792c35fae885099bcce5b239 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package cvss
import (
"strings"
)
// CVSS 2.0 vector.
type v2Vector []v2Metric
// Convert vector to string.
func (v v2Vector) String() string {
// convert to slice of metrics
metrics := []v2Metric(v)
// build vector
r := make([]string, len(metrics))
for i, m := range(metrics) {
r[i] = m.String()
}
// build and return string
return strings.Join(r, "/")
}
// Return CVSS version.
func (v2Vector) Version() Version {
return V20
}
// Return metrics in this vector.
func (v v2Vector) Metrics() []Metric {
// build result
r := make([]Metric, len(v))
for i, m := range(v) {
r[i] = m
}
// return result
return r
}
// Create CVSS 2.0 vector from string.
func newV2Vector(s string) (Vector, error) {
strs := strings.Split(s, "/")
r := make([]v2Metric, len(strs))
// walk metric strings
for i, ms := range(strs) {
// convert string to vector
m, err := getV2MetricFromString(ms)
if err != nil {
return nil, err
}
// add to results
r[i] = m
}
// build and return vector
return v2Vector(r), nil
}
|