2017-10-23 20:42:56 +00:00
|
|
|
package vault
|
|
|
|
|
2018-01-19 10:24:40 +00:00
|
|
|
import "context"
|
|
|
|
|
2017-10-23 20:42:56 +00: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 10:24:40 +00:00
|
|
|
func (b *BarrierEncryptorAccess) Encrypt(ctx context.Context, key string, plaintext []byte) ([]byte, error) {
|
2018-01-19 10:31:55 +00:00
|
|
|
return b.barrierEncryptor.Encrypt(ctx, key, plaintext)
|
2017-10-23 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 10:24:40 +00:00
|
|
|
func (b *BarrierEncryptorAccess) Decrypt(ctx context.Context, key string, ciphertext []byte) ([]byte, error) {
|
2018-01-19 10:31:55 +00:00
|
|
|
return b.barrierEncryptor.Decrypt(ctx, key, ciphertext)
|
2017-10-23 20:42:56 +00:00
|
|
|
}
|