@@ -19,9 +19,7 @@ import (
1919 "context"
2020 "errors"
2121 "fmt"
22-
2322 "strings"
24- "time"
2523
2624 jsoniter "github.com/json-iterator/go"
2725
@@ -42,81 +40,14 @@ import (
4240// - a pkg or source depending on what is represented by the name/URI
4341// - An IsOccurence input spec which will generate a predicate for each occurence
4442
45- // DigestSet is a set of digests keyed by algorithm name (e.g. "sha256").
46- type DigestSet = map [string ]string
47-
48- // ProvenanceMaterial represents a material used in a provenance attestation.
49- type ProvenanceMaterial struct {
50- URI string `json:"uri"`
51- Digest DigestSet `json:"digest,omitempty"`
52- }
53-
54- // ProvenanceBuilder identifies the entity that executed the build steps.
55- type ProvenanceBuilder struct {
56- ID string `json:"id"`
57- }
58-
5943const (
6044 PredicateSLSAProvenanceV01 = "https://slsa.dev/provenance/v0.1"
6145 PredicateSLSAProvenanceV02 = "https://slsa.dev/provenance/v0.2"
6246
63- // PredicateSLSAProvenancev1 is the predicate type for SLSAv1.0 provenance.
64- PredicateSLSAProvenancev1 = "https://slsa.dev/provenance/v1"
47+ // PredicateSLSAProvenanceV1 is the predicate type for SLSAv1.0 provenance.
48+ PredicateSLSAProvenanceV1 = "https://slsa.dev/provenance/v1"
6549)
6650
67- // ProvenancePredicateV01 is the SLSA v0.1 provenance predicate.
68- type ProvenancePredicateV01 struct {
69- Builder ProvenanceBuilder `json:"builder"`
70- Recipe ProvenanceRecipe `json:"recipe"`
71- Metadata * ProvenanceMetadataV01 `json:"metadata,omitempty"`
72- Materials []ProvenanceMaterial `json:"materials,omitempty"`
73- }
74-
75- // ProvenanceRecipe describes how the artifact was produced (SLSA v0.1).
76- type ProvenanceRecipe struct {
77- Type string `json:"type"`
78- DefinedInMaterial * int `json:"definedInMaterial,omitempty"`
79- EntryPoint string `json:"entryPoint,omitempty"`
80- Arguments interface {} `json:"arguments,omitempty"`
81- Environment interface {} `json:"environment,omitempty"`
82- }
83-
84- // ProvenanceMetadataV01 holds build metadata for SLSA v0.1 provenance.
85- type ProvenanceMetadataV01 struct {
86- BuildInvocationID string `json:"buildInvocationId,omitempty"`
87- BuildStartedOn * time.Time `json:"buildStartedOn,omitempty"`
88- BuildFinishedOn * time.Time `json:"buildFinishedOn,omitempty"`
89- Completeness struct {
90- Arguments bool `json:"arguments"`
91- Environment bool `json:"environment"`
92- Materials bool `json:"materials"`
93- } `json:"completeness"`
94- Reproducible bool `json:"reproducible"`
95- }
96-
97- // ProvenancePredicateV02 is the SLSA v0.2 provenance predicate.
98- type ProvenancePredicateV02 struct {
99- Builder ProvenanceBuilder `json:"builder"`
100- BuildType string `json:"buildType"`
101- Invocation interface {} `json:"invocation,omitempty"`
102- BuildConfig interface {} `json:"buildConfig,omitempty"`
103- Metadata * ProvenanceMetadataV02 `json:"metadata,omitempty"`
104- Materials []ProvenanceMaterial `json:"materials,omitempty"`
105- }
106-
107- // ProvenanceMetadataV02 holds build metadata for SLSA v0.2 provenance.
108- type ProvenanceMetadataV02 struct {
109- BuildInvocationID string `json:"buildInvocationId,omitempty"`
110- BuildStartedOn * time.Time `json:"buildStartedOn,omitempty"`
111- BuildFinishedOn * time.Time `json:"buildFinishedOn,omitempty"`
112- Completeness struct {
113- Parameters bool `json:"parameters"`
114- Environment bool `json:"environment"`
115- Materials bool `json:"materials"`
116- } `json:"completeness"`
117- Reproducible bool `json:"reproducible"`
118- }
119-
12051var ErrMetadataNil = errors .New ("SLSA Metadata is nil" )
12152var ErrBuilderNil = errors .New ("SLSA Builder is nil" )
12253var json = jsoniter .ConfigCompatibleWithStandardLibrary
@@ -209,7 +140,7 @@ func (s *slsaParser) getMaterials() error {
209140 if err := s .getMaterials0 (s .pred02 .Materials ); err != nil {
210141 return err
211142 }
212- case PredicateSLSAProvenancev1 :
143+ case PredicateSLSAProvenanceV1 :
213144 if s .pred1 .BuildDefinition == nil {
214145 return errors .New ("SLSA1 buildDefinition is nil" )
215146 }
@@ -370,7 +301,7 @@ func (s *slsaParser) getSLSA() error {
370301 if data , err = json .Marshal (s .pred02 ); err != nil {
371302 return fmt .Errorf ("could not marshal SLSA02: %w" , err )
372303 }
373- case PredicateSLSAProvenancev1 :
304+ case PredicateSLSAProvenanceV1 :
374305 if err := fillSLSA1 (inp , s .pred1 ); err != nil {
375306 return fmt .Errorf ("could not fill SLSA1: %w" , err )
376307 }
@@ -409,7 +340,7 @@ func (s *slsaParser) getBuilder() error {
409340 s .builder .Uri = s .pred01 .Builder .ID
410341 case PredicateSLSAProvenanceV02 :
411342 s .builder .Uri = s .pred02 .Builder .ID
412- case PredicateSLSAProvenancev1 :
343+ case PredicateSLSAProvenanceV1 :
413344 if s .pred1 .RunDetails == nil || s .pred1 .RunDetails .Builder == nil {
414345 return ErrBuilderNil
415346 }
@@ -440,7 +371,7 @@ func (s *slsaParser) parseSlsaPredicate(p []byte) error {
440371 if err := json .Unmarshal (predBytes , s .pred02 ); err != nil {
441372 return fmt .Errorf ("Could not unmarshal v0.2 SLSA provenance statement : %w" , err )
442373 }
443- case PredicateSLSAProvenancev1 :
374+ case PredicateSLSAProvenanceV1 :
444375 s .pred1 = & slsa1.Provenance {}
445376 if err := protojson .Unmarshal (predBytes , s .pred1 ); err != nil {
446377 return fmt .Errorf ("Could not unmarshal v1.0 SLSA provenance statement : %w" , err )
0 commit comments