aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/feed.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/feed/feed.go')
-rw-r--r--internal/feed/feed.go60
1 files changed, 15 insertions, 45 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index 93a4a8f..a04c3ce 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -3,16 +3,10 @@ package feed
import (
"encoding/json"
"fmt"
- // "strconv"
)
const (
- AdjacentNetwork = iota // Adjacent Network attack vector.
- Network // Network attack vector.
- Local // Local attack vector.
- Physical // Physical attack vector.
-
- None // no priv req/user interaction
+ None = iota // no priv req/user interaction
Low // low complexity/priv req
Medium // medium complexity/priv req
High // high complexity/priv req
@@ -35,36 +29,6 @@ const (
// TODO: parse cpe
-// CVSS attack vector
-type AttackVector int
-
-// Unmarshal CVSS attack vector from JSON.
-func (me *AttackVector) 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 "ADJACENT_NETWORK":
- *me = AdjacentNetwork
- case "LOCAL":
- *me = Local
- case "NETWORK":
- *me = Network
- case "PHYSICAL":
- *me = Physical
- default:
- // return error
- return fmt.Errorf("unknown attack vector: %s", s)
- }
-
- // return success
- return nil
-}
-
// CVSS attack complexity
type AttackComplexity int
@@ -258,10 +222,16 @@ func (me *Severity) UnmarshalJSON(b []byte) error {
return nil
}
-type AccessVector int
+type V2AccessVector byte
+
+const (
+ V2AVAdjacentNetwork V2AccessVector = iota
+ V2AVLocal
+ V2AVNetwork
+)
// Unmarshal CVSS V2 access vector from JSON.
-func (me *AccessVector) UnmarshalJSON(b []byte) error {
+func (me *V2AccessVector) UnmarshalJSON(b []byte) error {
// decode string, check for error
var s string
if err := json.Unmarshal(b, &s); err != nil {
@@ -271,14 +241,14 @@ func (me *AccessVector) UnmarshalJSON(b []byte) error {
// check value
switch s {
case "ADJACENT_NETWORK":
- *me = AdjacentNetwork
+ *me = V2AVAdjacentNetwork
case "LOCAL":
- *me = Local
+ *me = V2AVLocal
case "NETWORK":
- *me = Network
+ *me = V2AVNetwork
default:
// return error
- return fmt.Errorf("unknown CVSS access vector: %s", s)
+ return fmt.Errorf("unknown CVSS v2 access vector: %s", s)
}
// return success
@@ -511,7 +481,7 @@ type CvssV3 struct {
VectorString string `json:"vectorString"`
// attack vector
- AttackVector AttackVector `json:"attackVector"`
+ AttackVector V3AttackVector `json:"attackVector"`
// attack complexity
AttackComplexity AttackComplexity `json:"attackComplexity"`
@@ -554,7 +524,7 @@ type CvssV2 struct {
VectorString string `json:"vectorString"`
// attack vector
- AccessVector AccessVector `json:"accessVector"`
+ AccessVector V2AccessVector `json:"accessVector"`
// attack complexity
AccessComplexity AccessComplexity `json:"accessComplexity"`