File: toc.go

package info (click to toggle)
golang-github-containers-storage 1.59.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,184 kB
  • sloc: sh: 630; ansic: 389; makefile: 143; awk: 12
file content (41 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package toc

import (
	"errors"

	"github.com/containers/storage/pkg/chunked/internal/minimal"
	digest "github.com/opencontainers/go-digest"
)

// tocJSONDigestAnnotation is the annotation key for the digest of the estargz
// TOC JSON.
// It is defined in github.com/containerd/stargz-snapshotter/estargz as TOCJSONDigestAnnotation
// Duplicate it here to avoid a dependency on the package.
const tocJSONDigestAnnotation = "containerd.io/snapshot/stargz/toc.digest"

// GetTOCDigest returns the digest of the TOC as recorded in the annotations.
// This function retrieves a digest that represents the content of a
// table of contents (TOC) from the image's annotations.
// This is an experimental feature and may be changed/removed in the future.
func GetTOCDigest(annotations map[string]string) (*digest.Digest, error) {
	d1, ok1 := annotations[tocJSONDigestAnnotation]
	d2, ok2 := annotations[minimal.ManifestChecksumKey]
	switch {
	case ok1 && ok2:
		return nil, errors.New("both zstd:chunked and eStargz TOC found")
	case ok1:
		d, err := digest.Parse(d1)
		if err != nil {
			return nil, err
		}
		return &d, nil
	case ok2:
		d, err := digest.Parse(d2)
		if err != nil {
			return nil, err
		}
		return &d, nil
	default:
		return nil, nil
	}
}