github.com/trustbloc/kms-go@v1.1.2/mock/secretlock/mock_secretlock.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package secretlock
     8  
     9  import (
    10  	"github.com/trustbloc/kms-go/spi/secretlock"
    11  )
    12  
    13  // MockSecretLock mocking a Secret Lock service.
    14  type MockSecretLock struct {
    15  	ValEncrypt string
    16  	ValDecrypt string
    17  	ErrEncrypt error
    18  	ErrDecrypt error
    19  }
    20  
    21  // Encrypt req for master key in keyURI.
    22  func (m *MockSecretLock) Encrypt(keyURI string, req *secretlock.EncryptRequest) (*secretlock.EncryptResponse, error) {
    23  	if m.ErrEncrypt != nil {
    24  		return nil, m.ErrEncrypt
    25  	}
    26  
    27  	return &secretlock.EncryptResponse{Ciphertext: m.ValEncrypt}, nil
    28  }
    29  
    30  // Decrypt req for master key in keyURI.
    31  func (m *MockSecretLock) Decrypt(keyURI string, req *secretlock.DecryptRequest) (*secretlock.DecryptResponse, error) {
    32  	if m.ErrDecrypt != nil {
    33  		return nil, m.ErrDecrypt
    34  	}
    35  
    36  	return &secretlock.DecryptResponse{Plaintext: m.ValDecrypt}, nil
    37  }