...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package empty
17
18 import (
19 "errors"
20 "fmt"
21
22 "github.com/google/go-containerregistry/pkg/name"
23 v1 "github.com/google/go-containerregistry/pkg/v1"
24 "github.com/google/go-containerregistry/pkg/v1/empty"
25 "github.com/sigstore/cosign/v2/pkg/oci"
26 )
27
28 type signedImage struct {
29 v1.Image
30 digest v1.Hash
31 signature oci.Signatures
32 attestations oci.Signatures
33 }
34
35 func (se *signedImage) Signatures() (oci.Signatures, error) {
36 return se.signature, nil
37 }
38
39 func (se *signedImage) Attestations() (oci.Signatures, error) {
40 return se.attestations, nil
41 }
42
43 func (se *signedImage) Attachment(name string) (oci.File, error) {
44 return nil, errors.New("no attachments")
45 }
46
47 func (se *signedImage) Digest() (v1.Hash, error) {
48 if se.digest.Hex == "" {
49 return v1.Hash{}, fmt.Errorf("digest not available")
50 }
51 return se.digest, nil
52 }
53
54 func SignedImage(ref name.Reference) (oci.SignedImage, error) {
55 var err error
56 d := v1.Hash{}
57 base := empty.Image
58 if digest, ok := ref.(name.Digest); ok {
59 d, err = v1.NewHash(digest.DigestStr())
60 if err != nil {
61 return nil, err
62 }
63 }
64 return &signedImage{
65 Image: base,
66 digest: d,
67 signature: Signatures(),
68 attestations: Signatures(),
69 }, nil
70 }
71
View as plain text