| 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 |
} |