Skip to content

Commit d5221fe

Browse files
committed
Refactor getOCIDescriptorContents to use digest.Digest parameter
Signed-off-by: Ayato Tokubi <[email protected]>
1 parent dded690 commit d5221fe

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

image/oci/layout/oci_dest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (d *ociImageDestination) putSignaturesToSigstoreAttachment(ctx context.Cont
422422
signConfig.RootFS.Type = "layers"
423423
} else {
424424
logrus.Debugf("Fetching sigstore attachment config %s", signManifest.Config.Digest.String())
425-
configBlob, err := d.ref.getOCIDescriptorContents(signManifest.Config, iolimits.MaxConfigBodySize, d.sharedBlobDir)
425+
configBlob, err := d.ref.getOCIDescriptorContents(signManifest.Config.Digest, iolimits.MaxConfigBodySize, d.sharedBlobDir)
426426
if err != nil {
427427
return err
428428
}

image/oci/layout/oci_transport.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,27 +392,27 @@ func (ref ociReference) getBlob(d digest.Digest, sharedBlobDir string) (io.ReadC
392392
return r, fi.Size(), nil
393393
}
394394

395-
func (ref ociReference) getOCIDescriptorContents(desc imgspecv1.Descriptor, maxSize int, sharedBlobDir string) ([]byte, error) {
396-
if err := desc.Digest.Validate(); err != nil { // .Algorithm() might panic without this check
397-
return nil, fmt.Errorf("invalid digest %q: %w", desc.Digest.String(), err)
395+
func (ref ociReference) getOCIDescriptorContents(dgst digest.Digest, maxSize int, sharedBlobDir string) ([]byte, error) {
396+
if err := dgst.Validate(); err != nil { // .Algorithm() might panic without this check
397+
return nil, fmt.Errorf("invalid digest %q: %w", dgst.String(), err)
398398
}
399-
digestAlgorithm := desc.Digest.Algorithm()
399+
digestAlgorithm := dgst.Algorithm()
400400
if !digestAlgorithm.Available() {
401-
return nil, fmt.Errorf("invalid digest %q: unsupported digest algorithm %q", desc.Digest.String(), digestAlgorithm.String())
401+
return nil, fmt.Errorf("invalid digest %q: unsupported digest algorithm %q", dgst.String(), digestAlgorithm.String())
402402
}
403403

404-
reader, _, err := ref.getBlob(desc.Digest, sharedBlobDir)
404+
reader, _, err := ref.getBlob(dgst, sharedBlobDir)
405405
if err != nil {
406406
return nil, err
407407
}
408408
defer reader.Close()
409409
payload, err := iolimits.ReadAtMost(reader, maxSize)
410410
if err != nil {
411-
return nil, fmt.Errorf("reading blob %s in %s: %w", desc.Digest.String(), ref.image, err)
411+
return nil, fmt.Errorf("reading blob %s in %s: %w", dgst.String(), ref.image, err)
412412
}
413413
actualDigest := digestAlgorithm.FromBytes(payload)
414-
if actualDigest != desc.Digest {
415-
return nil, fmt.Errorf("digest mismatch, expected %q, got %q", desc.Digest.String(), actualDigest.String())
414+
if actualDigest != dgst {
415+
return nil, fmt.Errorf("digest mismatch, expected %q, got %q", dgst.String(), actualDigest.String())
416416
}
417417
return payload, nil
418418
}

0 commit comments

Comments
 (0)