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 {
|
|
|
|
return fmt.Sprintf("%s-%s", Acronym, w.ID)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2021-05-10 09:08:04 +01:00
|
|
|
|
2021-05-31 09:44:12 +01:00
|
|
|
// InformationURI link to the published CWE PDF
|
2021-05-10 09:08:04 +01:00
|
|
|
func InformationURI() string {
|
|
|
|
return fmt.Sprintf("https://cwe.mitre.org/data/published/cwe_v%s.pdf/", Version)
|
|
|
|
}
|
|
|
|
|
2021-05-31 09:44:12 +01:00
|
|
|
// DownloadURI link to the zipped XML of the CWE list
|
2021-05-10 09:08:04 +01:00
|
|
|
func DownloadURI() string {
|
|
|
|
return fmt.Sprintf("https://cwe.mitre.org/data/xml/cwec_v%s.xml.zip", Version)
|
|
|
|
}
|