forked from gopasspw/gopass
/
crypto.go
63 lines (50 loc) · 1.78 KB
/
crypto.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package backend
import (
"context"
"github.com/blang/semver"
)
// CryptoBackend is a cryptographic backend
type CryptoBackend int
const (
// Plain is a no-op crypto backend
Plain CryptoBackend = iota
// GPGCLI is a gpg-cli based crypto backend
GPGCLI
// XC is an experimental crypto backend
XC
// OpenPGP is a GPG1.x compatible pure-Go crypto backend
OpenPGP
// Vault is Hashicorp Vault backend
Vault
)
func (c CryptoBackend) String() string {
return cryptoNameFromBackend(c)
}
// Keyring is a public/private key manager
type Keyring interface {
ImportPublicKey(ctx context.Context, key []byte) error
ExportPublicKey(ctx context.Context, id string) ([]byte, error)
ListPublicKeyIDs(ctx context.Context) ([]string, error)
ListPrivateKeyIDs(ctx context.Context) ([]string, error)
FindPublicKeys(ctx context.Context, needles ...string) ([]string, error)
FindPrivateKeys(ctx context.Context, needles ...string) ([]string, error)
FormatKey(ctx context.Context, id string) string
NameFromKey(ctx context.Context, id string) string
EmailFromKey(ctx context.Context, id string) string
Fingerprint(ctx context.Context, id string) string
ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error)
CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error
CreatePrivateKey(ctx context.Context) error
}
// Crypto is a crypto backend
type Crypto interface {
Keyring
Encrypt(ctx context.Context, plaintext []byte, recipients []string) ([]byte, error)
Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error)
RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error)
Name() string
Version(context.Context) semver.Version
Initialized(ctx context.Context) error
Ext() string // filename extension
IDFile() string // recipient IDs
}