diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-02 01:32:05 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-02 01:32:05 -0500 |
commit | 153b1997de1b051de57d1b568bc0250e2888a38f (patch) | |
tree | c69b1f7fd710d72774abfa283612cea417817a5b /internal/feed/vector.go | |
parent | 7b1ca1c9c4304e8606399864563e6d1f877471de (diff) | |
download | cvez-153b1997de1b051de57d1b568bc0250e2888a38f.tar.bz2 cvez-153b1997de1b051de57d1b568bc0250e2888a38f.zip |
internal/feed: add vector and tests
Diffstat (limited to 'internal/feed/vector.go')
-rw-r--r-- | internal/feed/vector.go | 34 |
1 files changed, 34 insertions, 0 deletions
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 +} |