-
Notifications
You must be signed in to change notification settings - Fork 142
/
status.go
73 lines (63 loc) · 1.42 KB
/
status.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package types
import "encoding/json"
type Status int
var (
// Statuses is a list of statuses.
// VEX has 4 statuses: not-affected, affected, fixed, and under_investigation.
// cf. https://www.cisa.gov/sites/default/files/2023-04/minimum-requirements-for-vex-508c.pdf
//
// In addition to them, Red Hat has "will_not_fix" and "fix_deferred".
// cf. https://access.redhat.com/blogs/product-security/posts/2066793
//
// In addition to them, Ubuntu has "DNE", "ignored", "needed", "pending"
// https://askubuntu.com/a/1509706
Statuses = []string{
"unknown",
"not_affected",
"affected",
"fixed",
"under_investigation",
"will_not_fix",
"fix_deferred",
"end_of_life",
}
)
const (
StatusUnknown Status = iota
StatusNotAffected
StatusAffected
StatusFixed
StatusUnderInvestigation
StatusWillNotFix
StatusFixDeferred
StatusEndOfLife
)
func NewStatus(status string) Status {
for i, s := range Statuses {
if status == s {
return Status(i)
}
}
return StatusUnknown
}
func (s *Status) String() string {
idx := s.Index()
if idx < 0 || idx >= len(Statuses) {
idx = 0 // unknown
}
return Statuses[idx]
}
func (s *Status) Index() int {
return int(*s)
}
func (s *Status) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
func (s *Status) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
*s = NewStatus(str)
return nil
}