Skip to content

Commit 6b65ae3

Browse files
committed
Add a new Signer API for creating simple signing signatures with Sequoia-PGP
This API is proven end-to-end in containers#2876 and containers/skopeo#2645 , but it is not yet convenient to use becahse the Rust dependency has to be compiled manually. So, for now, add the API as a stub only; that allows building the CLIs and tests on top, and they will light up once the backend is added. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent d9a97d8 commit 6b65ae3

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

signature/simplesequoia/options.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package simplesequoia
2+
3+
import (
4+
"errors"
5+
"strings"
6+
)
7+
8+
type Option func(*simpleSequoiaSigner) error
9+
10+
// WithSequoiaHome returns an Option for NewSigner, specifying a Sequoia home directory to use.
11+
func WithSequoiaHome(sequoiaHome string) Option {
12+
return func(s *simpleSequoiaSigner) error {
13+
s.sequoiaHome = sequoiaHome
14+
return nil
15+
}
16+
}
17+
18+
// WithKeyFingerprint returns an Option for NewSigner, specifying a key to sign with, using the provided Sequoia-PGP key fingerprint.
19+
func WithKeyFingerprint(keyFingerprint string) Option {
20+
return func(s *simpleSequoiaSigner) error {
21+
s.keyFingerprint = keyFingerprint
22+
return nil
23+
}
24+
}
25+
26+
// WithPassphrase returns an Option for NewSigner, specifying a passphrase for the private key.
27+
func WithPassphrase(passphrase string) Option {
28+
return func(s *simpleSequoiaSigner) error {
29+
// The gpgme implementation can’t use passphrase with \n; reject it here for consistent behavior.
30+
// FIXME: We don’t need it in this API at all, but the "\n" check exists in the current call stack. That should go away.
31+
if strings.Contains(passphrase, "\n") {
32+
return errors.New("invalid passphrase: must not contain a line break")
33+
}
34+
s.passphrase = passphrase
35+
return nil
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package simplesequoia
2+
3+
import (
4+
"errors"
5+
6+
"github.com/containers/image/v5/signature/signer"
7+
)
8+
9+
// simpleSequoiaSigner is a signer.SignerImplementation implementation for simple signing signatures using Sequoia.
10+
type simpleSequoiaSigner struct {
11+
// This is not really used, we just keep the struct fields so that the With… Option functions can be compiled.
12+
13+
sequoiaHome string // "" if using the system's default
14+
keyFingerprint string
15+
passphrase string // "" if not provided.
16+
}
17+
18+
// NewSigner returns a signature.Signer which creates "simple signing" signatures using the user's default
19+
// Sequoia PGP configuration.
20+
//
21+
// The set of options must identify a key to sign with, probably using a WithKeyFingerprint.
22+
//
23+
// The caller must call Close() on the returned Signer.
24+
func NewSigner(opts ...Option) (*signer.Signer, error) {
25+
return nil, errors.New("Sequoia-PGP support is not enabled in this build")
26+
}

0 commit comments

Comments
 (0)