aboutsummaryrefslogtreecommitdiff
path: root/feed/vector.go
blob: 8b2dc9b34ee46a5174d673026db14f40cf3e8cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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) String() string {
  return me.Vector.String()
}

// Marshal CVSS vector to JSON.
func (me Vector) MarshalJSON() ([]byte, error) {
  return json.Marshal(me.String())
}