-
Notifications
You must be signed in to change notification settings - Fork 529
/
vulnerability.go
44 lines (36 loc) · 1.11 KB
/
vulnerability.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
package vulnerability
import (
"fmt"
"github.com/anchore/grype-db/pkg/db"
"github.com/anchore/grype/grype/version"
"github.com/anchore/syft/syft/pkg"
)
type Vulnerability struct {
Constraint version.Constraint
CPEs []pkg.CPE
ID string
RecordSource string
Namespace string
FixedInVersion string
}
func NewVulnerability(vuln db.Vulnerability) (*Vulnerability, error) {
format := version.ParseFormat(vuln.VersionFormat)
constraint, err := version.GetConstraint(vuln.VersionConstraint, format)
if err != nil {
return nil, fmt.Errorf("failed to parse constraint='%s' format='%s': %w", vuln.VersionConstraint, format, err)
}
return &Vulnerability{
Constraint: constraint,
ID: vuln.ID,
CPEs: make([]pkg.CPE, 0),
RecordSource: vuln.RecordSource,
Namespace: vuln.Namespace,
FixedInVersion: vuln.FixedInVersion,
}, nil
}
func (v Vulnerability) String() string {
return fmt.Sprintf("Vuln(id=%s constraint='%s')", v.ID, v.Constraint)
}
func (v *Vulnerability) hash() string {
return fmt.Sprintf("%s|%s|%+v", v.ID, v.Constraint, v.CPEs)
}