MCPcopy Create free account
hub / github.com/containers/image / getOCIDescriptorContents

Method getOCIDescriptorContents

docker/docker_client.go:1076–1102  ·  view source on GitHub ↗

getOCIDescriptorContents returns the contents a blob specified by descriptor in ref, which must fit within limit.

(ctx context.Context, ref dockerReference, desc imgspecv1.Descriptor, maxSize int, cache types.BlobInfoCache)

Source from the content-addressed store, hash-verified

1074
1075// getOCIDescriptorContents returns the contents a blob specified by descriptor in ref, which must fit within limit.
1076func (c *dockerClient) getOCIDescriptorContents(ctx context.Context, ref dockerReference, desc imgspecv1.Descriptor, maxSize int, cache types.BlobInfoCache) ([]byte, error) {
1077 // Note that this copies all kinds of attachments: attestations, and whatever else is there,
1078 // not just signatures. We leave the signature consumers to decide based on the MIME type.
1079
1080 if err := desc.Digest.Validate(); err != nil { // .Algorithm() might panic without this check
1081 return nil, fmt.Errorf("invalid digest %q: %w", desc.Digest.String(), err)
1082 }
1083 digestAlgorithm := desc.Digest.Algorithm()
1084 if !digestAlgorithm.Available() {
1085 return nil, fmt.Errorf("invalid digest %q: unsupported digest algorithm %q", desc.Digest.String(), digestAlgorithm.String())
1086 }
1087
1088 reader, _, err := c.getBlob(ctx, ref, manifest.BlobInfoFromOCI1Descriptor(desc), cache)
1089 if err != nil {
1090 return nil, err
1091 }
1092 defer reader.Close()
1093 payload, err := iolimits.ReadAtMost(reader, maxSize)
1094 if err != nil {
1095 return nil, fmt.Errorf("reading blob %s in %s: %w", desc.Digest.String(), ref.ref.Name(), err)
1096 }
1097 actualDigest := digestAlgorithm.FromBytes(payload)
1098 if actualDigest != desc.Digest {
1099 return nil, fmt.Errorf("digest mismatch, expected %q, got %q", desc.Digest.String(), actualDigest.String())
1100 }
1101 return payload, nil
1102}
1103
1104// isManifestUnknownError returns true iff err from fetchManifest is a “manifest unknown” error.
1105func isManifestUnknownError(err error) bool {

Calls 6

getBlobMethod · 0.95
ReadAtMostFunction · 0.92
StringMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected