github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/types/status.go (about) 1 package types 2 3 import "encoding/json" 4 5 type Status int 6 7 var ( 8 // Statuses is a list of statuses. 9 // VEX has 4 statuses: not-affected, affected, fixed, and under_investigation. 10 // cf. https://www.cisa.gov/sites/default/files/2023-04/minimum-requirements-for-vex-508c.pdf 11 // 12 // In addition to them, Red Hat has "will_not_fix" and "fix_deferred". 13 // cf. https://access.redhat.com/blogs/product-security/posts/2066793 14 Statuses = []string{ 15 "unknown", 16 "not_affected", 17 "affected", 18 "fixed", 19 "under_investigation", 20 "will_not_fix", 21 "fix_deferred", 22 "end_of_life", 23 } 24 ) 25 26 const ( 27 StatusUnknown Status = iota 28 StatusNotAffected 29 StatusAffected 30 StatusFixed 31 StatusUnderInvestigation 32 StatusWillNotFix // Red Hat specific 33 StatusFixDeferred 34 StatusEndOfLife 35 ) 36 37 func NewStatus(status string) Status { 38 for i, s := range Statuses { 39 if status == s { 40 return Status(i) 41 } 42 } 43 return StatusUnknown 44 } 45 46 func (s *Status) String() string { 47 idx := s.Index() 48 if idx < 0 || idx >= len(Statuses) { 49 idx = 0 // unknown 50 } 51 return Statuses[idx] 52 } 53 54 func (s *Status) Index() int { 55 return int(*s) 56 } 57 58 func (s *Status) MarshalJSON() ([]byte, error) { 59 return json.Marshal(s.String()) 60 } 61 62 func (s *Status) UnmarshalJSON(data []byte) error { 63 var str string 64 if err := json.Unmarshal(data, &str); err != nil { 65 return err 66 } 67 68 *s = NewStatus(str) 69 return nil 70 }