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

     1  /*
     2  Copyright Gen Digital Inc. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  package websuite
     7  
     8  import (
     9  	webcrypto "github.com/trustbloc/kms-go/crypto/webkms"
    10  	"github.com/trustbloc/kms-go/kms/webkms"
    11  )
    12  
    13  func makeFixedKey(
    14  	keyID string,
    15  	keyGetter *webkms.RemoteKMS,
    16  	crypto *webcrypto.RemoteCrypto,
    17  ) (*fixedKeyCrypto, error) {
    18  	keyURL, err := keyGetter.Get(keyID)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	return &fixedKeyCrypto{
    24  		keyURL: keyURL,
    25  		cr:     crypto,
    26  	}, nil
    27  }
    28  
    29  type fixedKeyCrypto struct {
    30  	keyURL interface{}
    31  	cr     *webcrypto.RemoteCrypto
    32  }
    33  
    34  func (f *fixedKeyCrypto) Sign(msg []byte) ([]byte, error) {
    35  	return f.cr.Sign(msg, f.keyURL)
    36  }
    37  
    38  func (f *fixedKeyCrypto) SignMulti(msgs [][]byte) ([]byte, error) {
    39  	return f.cr.SignMulti(msgs, f.keyURL)
    40  }
    41  
    42  func (f *fixedKeyCrypto) Verify(sig, msg []byte) error {
    43  	return f.cr.Verify(sig, msg, f.keyURL)
    44  }