github.com/trustbloc/kms-go@v1.1.2/kms/ariesProviderWrapper.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package kms 8 9 import ( 10 "errors" 11 "fmt" 12 13 "github.com/trustbloc/kms-go/spi/kms" 14 "github.com/trustbloc/kms-go/spi/storage" 15 ) 16 17 // AriesWrapperStoreName is the store name used when creating a KMS store using kms.NewAriesProviderWrapper. 18 const AriesWrapperStoreName = "kmsdb" 19 20 type ariesProviderKMSStoreWrapper struct { 21 store storage.Store 22 } 23 24 func (a *ariesProviderKMSStoreWrapper) Put(keysetID string, key []byte) error { 25 return a.store.Put(keysetID, key) 26 } 27 28 func (a *ariesProviderKMSStoreWrapper) Get(keysetID string) ([]byte, error) { 29 key, err := a.store.Get(keysetID) 30 if err != nil { 31 if errors.Is(err, storage.ErrDataNotFound) { 32 return nil, fmt.Errorf("%w. Underlying error: %s", 33 ErrKeyNotFound, err.Error()) 34 } 35 36 return nil, err 37 } 38 39 return key, nil 40 } 41 42 func (a *ariesProviderKMSStoreWrapper) Delete(keysetID string) error { 43 return a.store.Delete(keysetID) 44 } 45 46 // NewAriesProviderWrapper returns an implementation of the kms.Store interface that wraps an 47 // Aries provider implementation, allowing it to be used with a KMS. 48 func NewAriesProviderWrapper(provider storage.Provider) (kms.Store, error) { 49 store, err := provider.OpenStore(AriesWrapperStoreName) 50 if err != nil { 51 return nil, err 52 } 53 54 storeWrapper := ariesProviderKMSStoreWrapper{store: store} 55 56 return &storeWrapper, nil 57 }