From 153b1997de1b051de57d1b568bc0250e2888a38f Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 2 Feb 2022 01:32:05 -0500 Subject: internal/feed: add vector and tests --- internal/feed/vector.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 internal/feed/vector.go (limited to 'internal/feed/vector.go') diff --git a/internal/feed/vector.go b/internal/feed/vector.go new file mode 100644 index 0000000..a326c85 --- /dev/null +++ b/internal/feed/vector.go @@ -0,0 +1,34 @@ +// NVD JSON feed parser. +package feed + +import ( + "encoding/json" + "nvd/internal/cvss" +) + +// CVSS vector +type Vector struct { + // CVSS vector + Vector cvss.Vector +} + +// Unmarshal CVSS score from JSON. +func (me *Vector) UnmarshalJSON(b []byte) error { + // decode string, check for error + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + + // parse vector + vec, err := cvss.NewVector(s) + if err != nil { + return err + } + + // save result + me.Vector = vec + + // return success + return nil +} -- cgit v1.2.3