diff options
Diffstat (limited to 'internal/cvss/v31vector.go')
-rw-r--r-- | internal/cvss/v31vector.go | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/internal/cvss/v31vector.go b/internal/cvss/v31vector.go index 6e2acb6..f286ea0 100644 --- a/internal/cvss/v31vector.go +++ b/internal/cvss/v31vector.go @@ -1,6 +1,7 @@ package cvss import ( + "regexp" "strings" ) @@ -43,7 +44,7 @@ func (v v31Vector) Metrics() []Metric { } // create CVSS 3.1 vector from string. -func newV31Vector(s string) (Vector, error) { +func newV31Vector(s string) (v31Vector, error) { // strip version prefix, split into metric strings strs := strings.Split(s[len(v31Prefix):], "/") r := make([]v3Metric, len(strs)) @@ -64,7 +65,55 @@ func newV31Vector(s string) (Vector, error) { return v31Vector(r), nil } +// // Unmarshal CVSS 3.1 vector from JSON string. +// func (me *v31Vector) 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 := newV31Vector(s) +// if err != nil { +// return err +// } +// +// // save result, return success +// *me = r +// return nil +// } + +var v31VecRe = regexp.MustCompile( + "\\ACVSS:3\\.1(?:/(?:" + strings.Join([]string { + "(?:AV:[NALP])", + "(?:AC:[LH])", + "(?:PR:[NLH])", + "(?:UI:[NR])", + "(?:S:[UC])", + "(?:C:[HLN])", + "(?:I:[HLN])", + "(?:A:[HLN])", + "(?:E:[XHFPU])", + "(?:RL:[XUWTO])", + "(?:RC:[XCRU])", + "(?:CR:[XHML])", + "(?:IR:[XHML])", + "(?:AR:[XHML])", + "(?:MAV:[XNALP])", + "(?:MAC:[XLH])", + "(?:MPR:[XNLH])", + "(?:MUI:[XNR])", + "(?:MS:[XUC])", + "(?:MC:[XNLH])", + "(?:MI:[XNLH])", + "(?:MA:[XNLH])", + }, "|") + "))+\\z", +) + // Is the given string a CVSSv3.1 vector string? func isV31VectorString(s string) bool { - return (len(s) > len(v31Prefix)) && (s[:len(v31Prefix)] == v31Prefix); + return (len(s) > len(v31Prefix)) && + (s[:len(v31Prefix)] == v31Prefix) && + v31VecRe.MatchString(s) } |