aboutsummaryrefslogtreecommitdiff
path: root/feed/vector.go
diff options
context:
space:
mode:
Diffstat (limited to 'feed/vector.go')
-rw-r--r--feed/vector.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/feed/vector.go b/feed/vector.go
new file mode 100644
index 0000000..9f20dc6
--- /dev/null
+++ b/feed/vector.go
@@ -0,0 +1,39 @@
+// NVD JSON feed parser.
+package feed
+
+import (
+ "encoding/json"
+ "github.com/pablotron/cvez/cvss"
+)
+
+// CVSS vector
+type Vector struct {
+ // CVSS vector
+ Vector cvss.Vector
+}
+
+// Unmarshal CVSS vector 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
+}
+
+// Marshal CVSS vector to JSON.
+func (me Vector) MarshalJSON() ([]byte, error) {
+ return json.Marshal(me.Vector.String())
+}