File: signer.go

package info (click to toggle)
golang-github-containers-image 5.28.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,104 kB
  • sloc: sh: 194; makefile: 73
file content (47 lines) | stat: -rw-r--r-- 2,060 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
42
43
44
45
46
47
package signer

import (
	"context"

	"github.com/containers/image/v5/docker/reference"
	"github.com/containers/image/v5/internal/signature"
)

// Signer is an object, possibly carrying state, that can be used by copy.Image to sign one or more container images.
// This type is visible to external callers, so it has no public fields or methods apart from Close().
//
// The owner of a Signer must call Close() when done.
type Signer struct {
	implementation SignerImplementation
}

// NewSigner creates a public Signer from a SignerImplementation
func NewSigner(impl SignerImplementation) *Signer {
	return &Signer{implementation: impl}
}

func (s *Signer) Close() error {
	return s.implementation.Close()
}

// ProgressMessage returns a human-readable sentence that makes sense to write before starting to create a single signature.
// Alternatively, should SignImageManifest be provided a logging writer of some kind?
func ProgressMessage(signer *Signer) string {
	return signer.implementation.ProgressMessage()
}

// SignImageManifest invokes a SignerImplementation.
// This is a function, not a method, so that it can only be called by code that is allowed to import this internal subpackage.
func SignImageManifest(ctx context.Context, signer *Signer, manifest []byte, dockerReference reference.Named) (signature.Signature, error) {
	return signer.implementation.SignImageManifest(ctx, manifest, dockerReference)
}

// SignerImplementation is an object, possibly carrying state, that can be used by copy.Image to sign one or more container images.
// This interface is distinct from Signer so that implementations can be created outside of this package.
type SignerImplementation interface {
	// ProgressMessage returns a human-readable sentence that makes sense to write before starting to create a single signature.
	ProgressMessage() string
	// SignImageManifest creates a new signature for manifest m as dockerReference.
	SignImageManifest(ctx context.Context, m []byte, dockerReference reference.Named) (signature.Signature, error)
	Close() error
}