Skip to content

Commit 81729ee

Browse files
authored
set p.Block after parsing; other cleanup (sigstore#759)
Signed-off-by: Bob Callaway <bcallaway@google.com>
1 parent bfcf62e commit 81729ee

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

pkg/types/helm/provenance.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,15 @@ type SumCollection struct {
3838
}
3939

4040
func (p *Provenance) Unmarshal(reader io.Reader) error {
41-
4241
buf := &bytes.Buffer{}
4342
read, err := buf.ReadFrom(reader)
44-
4543
if err != nil {
4644
return errors.New("Failed to read from buffer")
47-
}
48-
49-
if read == 0 {
45+
} else if read == 0 {
5046
return errors.New("Provenance file contains no content")
5147
}
5248

53-
rawProvenanceFile := buf.Bytes()
54-
55-
block, _ := clearsign.Decode(rawProvenanceFile)
56-
49+
block, _ := clearsign.Decode(buf.Bytes())
5750
if block == nil {
5851
return errors.New("Unable to decode provenance file")
5952
}
@@ -62,16 +55,12 @@ func (p *Provenance) Unmarshal(reader io.Reader) error {
6255
return errors.New("Unable to locate armored signature in provenance file")
6356
}
6457

65-
p.Block = block
66-
67-
err = p.parseMessageBlock(block.Plaintext)
68-
69-
if err != nil {
58+
if err = p.parseMessageBlock(block.Plaintext); err != nil {
7059
return errors.Wrap(err, "Error occurred parsing message block")
7160
}
7261

62+
p.Block = block
7363
return nil
74-
7564
}
7665

7766
func (p *Provenance) parseMessageBlock(data []byte) error {
@@ -83,9 +72,7 @@ func (p *Provenance) parseMessageBlock(data []byte) error {
8372

8473
sc := &SumCollection{}
8574

86-
err := yaml.Unmarshal(parts[1], sc)
87-
88-
if err != nil {
75+
if err := yaml.Unmarshal(parts[1], sc); err != nil {
8976
return errors.Wrap(err, "Error occurred parsing SumCollection")
9077
}
9178

@@ -98,15 +85,10 @@ func (p *Provenance) GetChartAlgorithmHash() (string, string, error) {
9885

9986
if p.SumCollection == nil || p.SumCollection.Files == nil {
10087
return "", "", errors.New("Unable to locate chart hash")
101-
10288
}
10389

104-
files := p.SumCollection.Files
105-
106-
for _, value := range files {
107-
90+
for _, value := range p.SumCollection.Files {
10891
parts := strings.Split(value, ":")
109-
11092
if len(parts) != 2 {
11193
return "", "", errors.New("Invalid hash found in Provenance file")
11294
}

0 commit comments

Comments
 (0)