...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mutate
17
18 import (
19 "github.com/google/go-containerregistry/pkg/v1/types"
20 "github.com/sigstore/cosign/v2/pkg/cosign/bundle"
21 "github.com/sigstore/cosign/v2/pkg/oci"
22 )
23
24
25 type DupeDetector interface {
26 Find(oci.Signatures, oci.Signature) (oci.Signature, error)
27 }
28
29 type ReplaceOp interface {
30 Replace(oci.Signatures, oci.Signature) (oci.Signatures, error)
31 }
32
33 type SignOption func(*signOpts)
34
35 type signOpts struct {
36 dd DupeDetector
37 ro ReplaceOp
38 rct bool
39 }
40
41 func makeSignOpts(opts ...SignOption) *signOpts {
42 so := &signOpts{}
43 for _, opt := range opts {
44 opt(so)
45 }
46 return so
47 }
48
49
50
51 func WithDupeDetector(dd DupeDetector) SignOption {
52 return func(so *signOpts) {
53 so.dd = dd
54 }
55 }
56
57 func WithReplaceOp(ro ReplaceOp) SignOption {
58 return func(so *signOpts) {
59 so.ro = ro
60 }
61 }
62
63 func WithRecordCreationTimestamp(rct bool) SignOption {
64 return func(so *signOpts) {
65 so.rct = rct
66 }
67 }
68
69 type signatureOpts struct {
70 annotations map[string]string
71 bundle *bundle.RekorBundle
72 rfc3161Timestamp *bundle.RFC3161Timestamp
73 cert []byte
74 chain []byte
75 mediaType types.MediaType
76 }
77
78 type SignatureOption func(*signatureOpts)
79
80
81 func WithAnnotations(annotations map[string]string) SignatureOption {
82 return func(so *signatureOpts) {
83 so.annotations = annotations
84 }
85 }
86
87
88 func WithBundle(b *bundle.RekorBundle) SignatureOption {
89 return func(so *signatureOpts) {
90 so.bundle = b
91 }
92 }
93
94
95 func WithRFC3161Timestamp(b *bundle.RFC3161Timestamp) SignatureOption {
96 return func(so *signatureOpts) {
97 so.rfc3161Timestamp = b
98 }
99 }
100
101
102 func WithCertChain(cert, chain []byte) SignatureOption {
103 return func(so *signatureOpts) {
104 so.cert = cert
105 so.chain = chain
106 }
107 }
108
109
110 func WithMediaType(mediaType types.MediaType) SignatureOption {
111 return func(so *signatureOpts) {
112 so.mediaType = mediaType
113 }
114 }
115
116 func makeSignatureOption(opts ...SignatureOption) *signatureOpts {
117 so := &signatureOpts{}
118 for _, opt := range opts {
119 opt(so)
120 }
121 return so
122 }
123
View as plain text