@@ -23,6 +23,9 @@ import (
2323 "errors"
2424 "fmt"
2525 "io"
26+
27+ "github.com/google/uuid"
28+ "github.com/gowebpki/jcs"
2629)
2730
2831const (
@@ -164,6 +167,37 @@ type Component struct {
164167 ReleaseNotes * ReleaseNotes `json:"releaseNotes,omitempty" xml:"releaseNotes,omitempty"`
165168}
166169
170+ func (c Component ) bomReference () string {
171+ return c .BOMRef
172+ }
173+
174+ func (c * Component ) setBOMReference (ref string ) {
175+ c .BOMRef = ref
176+ }
177+
178+ // TODO: Can we solve this more elegantly?
179+ type componentRefSeed Component
180+
181+ func (c componentRefSeed ) MarshalJSON () ([]byte , error ) {
182+ c .BOMRef = ""
183+
184+ componentJSON , err := json .Marshal (Component (c ))
185+ if err != nil {
186+ return nil , err
187+ }
188+
189+ return jcs .Transform (componentJSON )
190+ }
191+
192+ func (c Component ) generateBOMReference () (string , error ) {
193+ componentJSON , err := json .Marshal (componentRefSeed (c ))
194+ if err != nil {
195+ return "" , err
196+ }
197+
198+ return uuid .NewSHA1 (uuid .MustParse ("369fac08-d4a0-452e-b4b1-de87a0f376c6" ), componentJSON ).String (), nil
199+ }
200+
167201type Composition struct {
168202 Aggregate CompositionAggregate `json:"aggregate" xml:"aggregate"`
169203 Assemblies * []BOMReference `json:"assemblies,omitempty" xml:"assemblies>assembly,omitempty"`
@@ -520,6 +554,17 @@ type Property struct {
520554 Value string `json:"value" xml:",innerxml"`
521555}
522556
557+ // referrer is an internal utility interface that is used
558+ // to address bom elements that have a BOM reference.
559+ type referrer interface {
560+ bomReference () string
561+ setBOMReference (ref string )
562+
563+ // generateBOMReference returns a new value intended to be used as BOM reference.
564+ // Given the same state of the referrer, generateBOMReference must return the same result.
565+ generateBOMReference () (string , error )
566+ }
567+
523568type ReleaseNotes struct {
524569 Type string `json:"type" xml:"type"`
525570 Title string `json:"title,omitempty" xml:"title,omitempty"`
@@ -570,6 +615,18 @@ type Service struct {
570615 ReleaseNotes * ReleaseNotes `json:"releaseNotes,omitempty" xml:"releaseNotes,omitempty"`
571616}
572617
618+ func (s Service ) bomReference () string {
619+ return s .BOMRef
620+ }
621+
622+ func (s * Service ) setBOMReference (ref string ) {
623+ s .BOMRef = ref
624+ }
625+
626+ func (s Service ) generateBOMReference () (string , error ) {
627+ return "" , nil
628+ }
629+
573630type Severity string
574631
575632const (
@@ -625,6 +682,18 @@ type Vulnerability struct {
625682 Affects * []Affects `json:"affects,omitempty" xml:"affects>target,omitempty"`
626683}
627684
685+ func (v Vulnerability ) bomReference () string {
686+ return v .BOMRef
687+ }
688+
689+ func (v * Vulnerability ) setBOMReference (ref string ) {
690+ v .BOMRef = ref
691+ }
692+
693+ func (v Vulnerability ) generateBOMReference () (string , error ) {
694+ return "" , nil
695+ }
696+
628697type VulnerabilityAnalysis struct {
629698 State ImpactAnalysisState `json:"state,omitempty" xml:"state,omitempty"`
630699 Justification ImpactAnalysisJustification `json:"justification,omitempty" xml:"justification,omitempty"`
0 commit comments