forked from 99designs/aws-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyring.go
50 lines (39 loc) · 990 Bytes
/
keyring.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
package keyring
import "errors"
type backend string
const (
KeychainBackend backend = "osxkeychain"
KWalletBackend backend = "kwallet"
)
var supportedBackends = map[backend]opener{}
func Open(name string, prefer ...backend) (Keyring, error) {
if len(prefer) == 0 {
for b := range supportedBackends {
prefer = append(prefer, b)
}
}
for _, b := range prefer {
for supported, f := range supportedBackends {
if b == supported {
return f(name)
}
}
}
return nil, ErrNoAvailImpl
}
type opener func(name string) (Keyring, error)
type Item struct {
Key string
Data []byte
Label string
Description string
TrustSelf bool
}
type Keyring interface {
Get(key string) (Item, error)
Set(item Item) error
Remove(key string) error
Keys() ([]string, error)
}
var ErrNoAvailImpl = errors.New("No keyring implementation for your platform available.")
var ErrKeyNotFound = errors.New("The specified item could not be found in the keyring.")