-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_test.go
122 lines (118 loc) · 2.26 KB
/
secret_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package aesext
import (
"reflect"
"testing"
)
func TestSecret_Encrypt(t *testing.T) {
type fields struct {
key []byte
salt []byte
}
type args struct {
origData []byte
}
tests := []struct {
name string
fields fields
args args
want []byte
wantErr bool
}{
{
"test key and salt a",
fields{
[]byte("test"),
[]byte("a")},
args{
[]byte("test")},
[]byte{0xce, 0xa2, 0x2a, 0x28, 0xaa, 0x9f, 0xef, 0x87,
0x09, 0xe2, 0x5d, 0xda, 0xf8, 0xc6, 0xc0, 0xe5},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
this, err := New(tt.fields.key, tt.fields.salt)
if err != nil {
t.Errorf("New() error = %v", err)
return
}
got, err := this.Encrypt(tt.args.origData)
if (err != nil) != tt.wantErr {
t.Errorf("Secret.Decrypt() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Secret.Encrypt() = %v, want %v", got, tt.want)
}
})
}
}
func TestSecret_Decrypt(t *testing.T) {
type fields struct {
key []byte
salt []byte
}
type args struct {
orgiData []byte
}
tests := []struct {
name string
fields fields
args args
want []byte
wantErr bool
}{
{
"test key and salt a",
fields{
[]byte("test"),
[]byte("a")},
args{
[]byte{0xce, 0xa2, 0x2a, 0x28, 0xaa, 0x9f, 0xef, 0x87,
0x09, 0xe2, 0x5d, 0xda, 0xf8, 0xc6, 0xc0, 0xe5},
},
[]byte("test"),
false,
},
{
"input not full blocks",
fields{
[]byte("test"),
[]byte("a"),
},
args{
[]byte{0xce},
},
nil,
true,
},
{
"invalid",
fields{[]byte("test"), []byte("a")},
args{
[]byte{0xce, 0xa2, 0x2a, 0x28, 0xaa, 0x9f, 0xef, 0x87,
0x09, 0xe2, 0x5d, 0xda, 0xf8, 0xc6, 0xc0, 0xf5},
},
nil,
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
this, err := New(tt.fields.key, tt.fields.salt)
if err != nil {
t.Errorf("New() error = %v", err)
return
}
got, err := this.Decrypt(tt.args.orgiData)
if (err != nil) != tt.wantErr {
t.Errorf("Secret.Decrypt() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Secret.Decrypt() = %v, want %v", got, tt.want)
}
})
}
}