github.com/trustbloc/kms-go@v1.1.2/wrapper/localsuite/localsuite.go (about)

     1  /*
     2  Copyright Gen Digital Inc. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  // Package localsuite provides an api.Suite using local kms and crypto implementations.
     7  package localsuite
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/trustbloc/kms-go/crypto/tinkcrypto"
    13  	"github.com/trustbloc/kms-go/kms/localkms"
    14  	kmsapi "github.com/trustbloc/kms-go/spi/kms"
    15  	"github.com/trustbloc/kms-go/spi/secretlock"
    16  	"github.com/trustbloc/kms-go/wrapper/api"
    17  )
    18  
    19  // NewLocalCryptoSuite initializes a wrapper.Suite using local kms and crypto
    20  // implementations, supporting all Suite APIs.
    21  func NewLocalCryptoSuite(
    22  	primaryKeyURI string,
    23  	keyStore kmsapi.Store,
    24  	secretLock secretlock.Service,
    25  ) (api.Suite, error) {
    26  	kms, err := localkms.New(primaryKeyURI, &kmsProv{
    27  		store: keyStore,
    28  		lock:  secretLock,
    29  	})
    30  	if err != nil {
    31  		return nil, fmt.Errorf("initializing local key manager: %w", err)
    32  	}
    33  
    34  	crypto, err := tinkcrypto.New()
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	return &suiteImpl{
    40  		kms:    kms,
    41  		crypto: crypto,
    42  	}, nil
    43  }
    44  
    45  type kmsProv struct {
    46  	store kmsapi.Store
    47  	lock  secretlock.Service
    48  }
    49  
    50  func (k *kmsProv) StorageProvider() kmsapi.Store {
    51  	return k.store
    52  }
    53  
    54  func (k *kmsProv) SecretLock() secretlock.Service {
    55  	return k.lock
    56  }