2021-05-05 17:54:32 +01:00
|
|
|
package cwe
|
|
|
|
|
|
|
|
import (
|
2021-05-07 15:54:34 +01:00
|
|
|
"encoding/json"
|
2021-05-05 17:54:32 +01:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Weakness defines a CWE weakness based on http://cwe.mitre.org/data/xsd/cwe_schema_v6.4.xsd
|
|
|
|
type Weakness struct {
|
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
}
|
|
|
|
|
2021-05-31 09:44:12 +01:00
|
|
|
// SprintURL format the CWE URL
|
2021-05-07 15:54:34 +01:00
|
|
|
func (w *Weakness) SprintURL() string {
|
2021-05-10 09:08:04 +01:00
|
|
|
return fmt.Sprintf("https://cwe.mitre.org/data/definitions/%s.html", w.ID)
|
2021-05-07 15:54:34 +01:00
|
|
|
}
|
|
|
|
|
2021-05-31 09:44:12 +01:00
|
|
|
// SprintID format the CWE ID
|
2021-05-07 15:54:34 +01:00
|
|
|
func (w *Weakness) SprintID() string {
|
2022-08-20 12:20:36 +01:00
|
|
|
id := "0000"
|
|
|
|
if w != nil {
|
|
|
|
id = w.ID
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s-%s", Acronym, id)
|
2021-05-07 15:54:34 +01:00
|
|
|
}
|
|
|
|
|
2021-05-31 09:44:12 +01:00
|
|
|
// MarshalJSON print only id and URL
|
2021-05-07 15:54:34 +01:00
|
|
|
func (w *Weakness) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
}{
|
|
|
|
ID: w.ID,
|
|
|
|
URL: w.SprintURL(),
|
|
|
|
})
|
2021-05-05 17:54:32 +01:00
|
|
|
}
|