-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathage-wrap_test.go
135 lines (131 loc) · 3.76 KB
/
age-wrap_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
123
124
125
126
127
128
129
130
131
132
133
134
135
package x25519
import (
"reflect"
"testing"
)
func Test_ageX25519Wrap_GeneratePubKeyAndPrivateKey(t *testing.T) {
type args struct {
pubPrefix string
privatePrefix string
}
tests := []struct {
name string
a *ageX25519Wrap
args args
wantPub string
wantPrivate string
wantErr bool
}{
{
name: "edge-device-controller",
a: &ageX25519Wrap{},
args: args{
pubPrefix: "edge-device-controller.pub-",
privatePrefix: "edge-device-controller-",
},
wantPub: "",
wantPrivate: "",
wantErr: false,
},
{
name: "empty prefix",
a: &ageX25519Wrap{},
args: args{
pubPrefix: "",
privatePrefix: "",
},
wantPub: "",
wantPrivate: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &ageX25519Wrap{}
gotPub, gotPrivate, err := a.GeneratePubKeyAndPrivateKey(tt.args.pubPrefix, tt.args.privatePrefix)
if (err != nil) != tt.wantErr {
t.Errorf("ageX25519Wrap.GeneratePubKeyAndPrivateKey() error = %+v, wantErr %v", err, tt.wantErr)
return
}
t.Logf("ageX25519Wrap.GeneratePubKeyAndPrivateKey() gotPub = %v, want %v", gotPub, tt.wantPub)
t.Logf("ageX25519Wrap.GeneratePubKeyAndPrivateKey() gotPrivate = %v, want %v", gotPrivate, tt.wantPrivate)
})
}
}
func Test_ageX25519Wrap_EncryptByPubKeyWithPrefix(t *testing.T) {
type args struct {
in []byte
publicKey string
prefix string
}
tests := []struct {
name string
a *ageX25519Wrap
args args
wantOut []byte
wantErr bool
}{
{
name: "edge-device-controller",
a: &ageX25519Wrap{},
args: args{
in: []byte("hello, world"),
publicKey: "edge-device-controller.pub-1h8r5869agh9lxre6w5c24h3vf86tygfcvfhsy6l0u2d07r983ejsm99ur4",
prefix: "edge-device-controller.pub-",
},
wantOut: []byte{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &ageX25519Wrap{}
gotOut, err := a.EncryptByPubKeyWithPrefix(tt.args.in, tt.args.publicKey, tt.args.prefix)
if (err != nil) != tt.wantErr {
t.Errorf("ageX25519Wrap.EncryptByPubKeyWithPrefix() error = %v, wantErr %v", err, tt.wantErr)
return
}
// gotOut of running first time is diff with output of running second time, in two outputs of running
t.Logf("ageX25519Wrap.EncryptByPubKeyWithPrefix() = %q, want %q", gotOut, tt.wantOut)
})
}
}
func Test_ageX25519Wrap_DecryptByPrivateKeyWithPrefix(t *testing.T) {
type args struct {
in []byte
privateKey string
prefix string
}
tests := []struct {
name string
a *ageX25519Wrap
args args
wantOut []byte
wantErr bool
}{
{
name: "edge-device-controller",
a: &ageX25519Wrap{},
args: args{
in: []byte("age-encryption.org/v1\n-> X25519 3u929d1GSFKNiJ6u9ci3LV5vkxcoyCDMP3dh3U+OsTI\ny4C6M/Iu78kg+6EDeA7VnoA8VRm+dk1GPRbQ+FpxgD4\n--- SdZ3J3GcBBn8sdmH3U3N8eLZW+YVttBwYTsUDVROLWs\n\x8b\xc5\xfe\xe6zC\x8e\x81\xd2\xdfi\xb9|J\x0f\xfc\x10\xf6\xc8z؛ښs\x9c\x838\xec\xf7\x82\t\x9c\xd13g\t\x03\xe5YSO\xa0w"),
privateKey: "EDGE-DEVICE-CONTROLLER-1FCS2CKCQTLXVAXLN99R70PQGRCRZHM0KR5JG92WXYXFFPEMPV3DSVVF5DX",
prefix: "edge-device-controller-",
},
wantOut: []byte("hello, world"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &ageX25519Wrap{}
gotOut, err := a.DecryptByPrivateKeyWithPrefix(tt.args.in, tt.args.privateKey, tt.args.prefix)
if (err != nil) != tt.wantErr {
t.Errorf("ageX25519Wrap.DecryptByPrivateKeyWithPrefix() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotOut, tt.wantOut) {
t.Errorf("ageX25519Wrap.DecryptByPrivateKeyWithPrefix() = %v, want %v", gotOut, tt.wantOut)
}
})
}
}