From 3044aef20f4aecb7963e826b976c6d72a970cda1 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 1 Feb 2022 14:42:44 -0500 Subject: internal/feed: add v2version, v3version, tests --- internal/feed/feed.go | 62 ++------------------------------------------------- 1 file changed, 2 insertions(+), 60 deletions(-) (limited to 'internal/feed/feed.go') diff --git a/internal/feed/feed.go b/internal/feed/feed.go index affa5d2..3a6e695 100644 --- a/internal/feed/feed.go +++ b/internal/feed/feed.go @@ -1,15 +1,5 @@ package feed -import ( - "encoding/json" - "fmt" -) - -const ( - CvssVersion31 = iota // CVSS version 3.1 - CvssVersion20 // CVSS version 2.0 -) - // TODO: parse cpe, cve id // CVE metadata @@ -126,58 +116,10 @@ type ItemConfigurations struct { Nodes []ConfigurationNode `json:"nodes"` } -// CVSS version. -type CvssV3Version int - -// Unmarshal CVSS version from JSON. -func (me *CvssV3Version) UnmarshalJSON(b []byte) error { - // decode string, check for error - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - - // check value - switch s { - case "3.1": - *me = CvssVersion31 - default: - // return error - return fmt.Errorf("unknown CVSS V3 version: %s", s) - } - - // return success - return nil -} - -// CVSS V2 version. -type CvssV2Version int - -// Unmarshal CVSS version from JSON. -func (me *CvssV2Version) UnmarshalJSON(b []byte) error { - // decode string, check for error - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - - // check value - switch s { - case "2.0": - *me = CvssVersion20 - default: - // return error - return fmt.Errorf("unknown CVSS V2 version: %s", s) - } - - // return success - return nil -} - // CVSS V3 type CvssV3 struct { // CVSS V3 version - Version CvssV3Version `json:"version"` + Version V3Version `json:"version"` // CVSS V3 vector string (FIXME: add custom type) VectorString string `json:"vectorString"` @@ -220,7 +162,7 @@ type BaseMetricV3 struct { // CVSS V2 type CvssV2 struct { // CVSS V2 version - Version CvssV2Version `json:"version"` + Version V2Version `json:"version"` // CVSS V3 vector string (FIXME: add custom type) VectorString string `json:"vectorString"` -- cgit v1.2.3