forked from hashicorp/go-kms-wrapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envelope_test.go
45 lines (37 loc) · 896 Bytes
/
envelope_test.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
package wrapping
import (
"bytes"
"testing"
)
func TestEnvelope(t *testing.T) {
input := []byte("test")
env, err := NewEnvelope(nil).Encrypt(input, nil)
if err != nil {
t.Fatal(err)
}
output, err := NewEnvelope(nil).Decrypt(env, nil)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(input, output) {
t.Fatalf("expected the same text: expected %s, got %s", string(input), string(output))
}
}
func TestEnvelopeAAD(t *testing.T) {
input := []byte("test")
env, err := NewEnvelope(nil).Encrypt(input, []byte("foo"))
if err != nil {
t.Fatal(err)
}
output, err := NewEnvelope(nil).Decrypt(env, nil)
if err == nil {
t.Fatal("expected an error")
}
output, err = NewEnvelope(nil).Decrypt(env, []byte("foo"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(input, output) {
t.Fatalf("expected the same text: expected %s, got %s", string(input), string(output))
}
}