forked from ThalesGroup/gose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasymmetric_decryption_key_store.go
29 lines (26 loc) · 1.03 KB
/
asymmetric_decryption_key_store.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
package gose
// AsymmetricDecryptionKeyStoreImpl implements the AsymmetricDecryptionKeyStore interface providing AsymmetricDecryptionKey
// lookup capabilities.
type AsymmetricDecryptionKeyStoreImpl struct {
keys map[string]AsymmetricDecryptionKey
}
// Get returns a matching AsymmetricDecryptionKey fpr the given Key ID or an error (ErrUnknownKey) if the requested key
// cannot be found.
func (a *AsymmetricDecryptionKeyStoreImpl) Get(kid string) (k AsymmetricDecryptionKey, err error) {
// Find returns the key with matching kid or, if there's only a single key, return that.
if key, ok := a.keys[kid]; ok {
return key, nil
}
if len(a.keys) == 1 {
for _, key := range a.keys {
return key, nil
}
}
return nil, ErrUnknownKey
}
// NewAsymmetricDecryptionKeyStoreImpl creates a AsymmetricDecryptionKeyStoreImpl instances with the given keys.
func NewAsymmetricDecryptionKeyStoreImpl(keys map[string]AsymmetricDecryptionKey) (*AsymmetricDecryptionKeyStoreImpl, error) {
return &AsymmetricDecryptionKeyStoreImpl{
keys: keys,
}, nil
}