2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2024-01-02 21:36:20 +03:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 19:00:52 +03:00
|
|
|
|
2017-10-23 23:42:56 +03:00
|
|
|
package vault
|
|
|
|
|
2018-01-19 13:24:40 +03:00
|
|
|
import "context"
|
|
|
|
|
2017-10-23 23:42:56 +03:00
|
|
|
// BarrierEncryptorAccess is a wrapper around BarrierEncryptor that allows Core
|
|
|
|
// to expose its barrier encrypt/decrypt operations through BarrierEncryptorAccess()
|
|
|
|
// while restricting the ability to modify Core.barrier itself.
|
|
|
|
type BarrierEncryptorAccess struct {
|
|
|
|
barrierEncryptor BarrierEncryptor
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ BarrierEncryptor = (*BarrierEncryptorAccess)(nil)
|
|
|
|
|
|
|
|
func NewBarrierEncryptorAccess(barrierEncryptor BarrierEncryptor) *BarrierEncryptorAccess {
|
|
|
|
return &BarrierEncryptorAccess{barrierEncryptor: barrierEncryptor}
|
|
|
|
}
|
|
|
|
|
2018-01-19 13:24:40 +03:00
|
|
|
func (b *BarrierEncryptorAccess) Encrypt(ctx context.Context, key string, plaintext []byte) ([]byte, error) {
|
2018-01-19 13:31:55 +03:00
|
|
|
return b.barrierEncryptor.Encrypt(ctx, key, plaintext)
|
2017-10-23 23:42:56 +03:00
|
|
|
}
|
|
|
|
|
2018-01-19 13:24:40 +03:00
|
|
|
func (b *BarrierEncryptorAccess) Decrypt(ctx context.Context, key string, ciphertext []byte) ([]byte, error) {
|
2018-01-19 13:31:55 +03:00
|
|
|
return b.barrierEncryptor.Decrypt(ctx, key, ciphertext)
|
2017-10-23 23:42:56 +03:00
|
|
|
}
|