diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
commit | 9c17b97cd0f83be3fff9fa4e87fd1d29052ea616 (patch) | |
tree | 0d97030a0d0c3ad983be281ce89f80571338887f /internal/cvss/v2vector.go | |
parent | 92400d731546557d110c9c3cc3906d700f83dda8 (diff) | |
download | cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.tar.bz2 cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.zip |
rename to github.com/pablotron/cvez, remove internal libs
Diffstat (limited to 'internal/cvss/v2vector.go')
-rw-r--r-- | internal/cvss/v2vector.go | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/internal/cvss/v2vector.go b/internal/cvss/v2vector.go deleted file mode 100644 index b1fca1f..0000000 --- a/internal/cvss/v2vector.go +++ /dev/null @@ -1,108 +0,0 @@ -package cvss - -import ( - // "encoding/json" - "regexp" - "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) (v2Vector, error) { - strs := strings.Split(s, "/") - r := make([]v2Metric, len(strs)) - - // walk metric strings - for i, ms := range(strs) { - // convert string to vector - m, err := getV2Metric(ms) - if err != nil { - return nil, err - } - - // add to results - r[i] = m - } - - // build and return vector - return v2Vector(r), nil -} - -// // Unmarshal CVSS 2.0 vector from JSON string. -// func (me *v2Vector) UnmarshalJSON(b []byte) error { -// // decode string, check for error -// var s string -// if err := json.Unmarshal(b, &s); err != nil { -// return err -// } -// -// // parse vector, check for error -// r, err := newV2Vector(s) -// if err != nil { -// // return error -// return err -// } -// -// // save result, return success -// *me = r -// return nil -// } - -var v2MetricRe = "(?:" + strings.Join([]string { - "(?:AV:[NAL])", - "(?:AC:[LMH])", - "(?:Au:[MSN])", - "(?:C:[NPC])", - "(?:I:[NPC])", - "(?:A:[NPC])", - "(?:E:(?:ND|U|POC|F|H))", - "(?:RL:(?:OF|TF|W|U|ND))", - "(?:RC:(?:UC|UR|C|ND))", - "(?:CDP:(?:N|L|LM|MH|H|ND))", - "(?:TD:(?:N|L|M|H|ND))", - "(?:CR:(?:L|M|H|ND))", - "(?:IR:(?:L|M|H|ND))", -}, "|") + ")" - -var v2VecRe = regexp.MustCompile( - "\\A" + v2MetricRe + "(?:/" + v2MetricRe + ")*\\z", -) - -// Is the given string a CVSS v2 vector string? -func isV2VectorString(s string) bool { - return len(s) > 0 && v2VecRe.MatchString(s) -} |