createSignatures creates signatures for manifest and an optional identity.
(ctx context.Context, manifest []byte, identity reference.Named)
| 77 | |
| 78 | // createSignatures creates signatures for manifest and an optional identity. |
| 79 | func (c *copier) createSignatures(ctx context.Context, manifest []byte, identity reference.Named) ([]internalsig.Signature, error) { |
| 80 | if len(c.signers) == 0 { |
| 81 | // We must exit early here, otherwise copies with no Docker reference wouldn’t be possible. |
| 82 | return nil, nil |
| 83 | } |
| 84 | |
| 85 | if identity != nil { |
| 86 | if reference.IsNameOnly(identity) { |
| 87 | return nil, fmt.Errorf("Sign identity must be a fully specified reference %s", identity.String()) |
| 88 | } |
| 89 | } else { |
| 90 | identity = c.dest.Reference().DockerReference() |
| 91 | if identity == nil { |
| 92 | return nil, fmt.Errorf("Cannot determine canonical Docker reference for destination %s", transports.ImageName(c.dest.Reference())) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | res := make([]internalsig.Signature, 0, len(c.signers)) |
| 97 | for signerIndex, signer := range c.signers { |
| 98 | msg := internalSigner.ProgressMessage(signer) |
| 99 | if len(c.signers) == 1 { |
| 100 | c.Printf("Creating signature: %s\n", msg) |
| 101 | } else { |
| 102 | c.Printf("Creating signature %d: %s\n", signerIndex+1, msg) |
| 103 | } |
| 104 | newSig, err := internalSigner.SignImageManifest(ctx, signer, manifest, identity) |
| 105 | if err != nil { |
| 106 | if len(c.signers) == 1 { |
| 107 | return nil, fmt.Errorf("creating signature: %w", err) |
| 108 | } else { |
| 109 | return nil, fmt.Errorf("creating signature %d: %w", signerIndex+1, err) |
| 110 | } |
| 111 | } |
| 112 | res = append(res, newSig) |
| 113 | } |
| 114 | return res, nil |
| 115 | } |