-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
seal_testing.go
59 lines (48 loc) · 1.23 KB
/
seal_testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package seal
import (
"context"
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping"
)
type TestSealOpts struct {
Logger hclog.Logger
StoredKeys StoredKeysSupport
Secret []byte
Name string
}
func NewTestSeal(opts *TestSealOpts) *Access {
if opts == nil {
opts = new(TestSealOpts)
}
return &Access{
Wrapper: wrapping.NewTestWrapper(opts.Secret),
OverriddenType: opts.Name,
}
}
func NewToggleableTestSeal(opts *TestSealOpts) (*Access, *error) {
if opts == nil {
opts = new(TestSealOpts)
}
w := &ToggleableWrapper{Wrapper: wrapping.NewTestWrapper(opts.Secret)}
return &Access{
Wrapper: w,
OverriddenType: opts.Name,
}, &w.Error
}
type ToggleableWrapper struct {
wrapping.Wrapper
Error error
}
func (t ToggleableWrapper) Encrypt(ctx context.Context, bytes []byte, bytes2 []byte) (*wrapping.EncryptedBlobInfo, error) {
if t.Error != nil {
return nil, t.Error
}
return t.Wrapper.Encrypt(ctx, bytes, bytes2)
}
func (t ToggleableWrapper) Decrypt(ctx context.Context, info *wrapping.EncryptedBlobInfo, bytes []byte) ([]byte, error) {
if t.Error != nil {
return nil, t.Error
}
return t.Wrapper.Decrypt(ctx, info, bytes)
}
var _ wrapping.Wrapper = &ToggleableWrapper{}