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)
| 1074 | |
| 1075 | // getOCIDescriptorContents returns the contents a blob specified by descriptor in ref, which must fit within limit. |
| 1076 | func (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. |
| 1105 | func isManifestUnknownError(err error) bool { |
no test coverage detected