aboutsummaryrefslogtreecommitdiff
path: root/cvss/vector.go
blob: 0c5fdbb34d24ad5c2db1128a5307b5c0e68a39f5 (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
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

  // Get base, temporal, and environment scores for vector.
  Scores() (Scores, 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)
  }
}