github.com/blend/go-sdk@v1.20220411.3/vault/mock_vault_transit.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package vault 9 10 import ( 11 "context" 12 "encoding/base64" 13 ) 14 15 // Assert MockTransitClient implements TransitClient 16 var ( 17 _ Client = MockTransitClient{} 18 _ TransitClient = MockTransitClient{} 19 ) 20 21 // MockTransitClient skips interactions with the vault for encryption/decryption 22 type MockTransitClient struct { 23 Client 24 } 25 26 // Encrypt just returns the input in the mock 27 func (m MockTransitClient) Encrypt(ctx context.Context, key string, context, data []byte) (string, error) { 28 return base64.StdEncoding.EncodeToString(data), nil 29 } 30 31 // TransitHMAC just returns the input 32 func (m MockTransitClient) TransitHMAC(ctx context.Context, key string, input []byte) ([]byte, error) { 33 return input, nil 34 } 35 36 // Decrypt just returns the input in the mock 37 func (m MockTransitClient) Decrypt(ctx context.Context, key string, context []byte, ciphertext string) ([]byte, error) { 38 return base64.StdEncoding.DecodeString(ciphertext) 39 } 40 41 // BatchEncrypt just returns the input 42 func (m MockTransitClient) BatchEncrypt(ctx context.Context, key string, batchInput BatchTransitInput) ([]string, error) { 43 var res []string 44 for i := range batchInput.BatchTransitInputItems { 45 data := batchInput.BatchTransitInputItems[i].Plaintext 46 res = append(res, base64.StdEncoding.EncodeToString(data)) 47 } 48 return res, nil 49 } 50 51 // BatchDecrypt just returns the input 52 func (m MockTransitClient) BatchDecrypt(ctx context.Context, key string, batchInput BatchTransitInput) ([][]byte, error) { 53 var res [][]byte 54 for i := range batchInput.BatchTransitInputItems { 55 data, err := base64.StdEncoding.DecodeString(batchInput.BatchTransitInputItems[i].Ciphertext) 56 if err != nil { 57 return nil, err 58 } 59 res = append(res, data) 60 } 61 return res, nil 62 }