-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_test.go
More file actions
75 lines (65 loc) · 1.45 KB
/
main_test.go
File metadata and controls
75 lines (65 loc) · 1.45 KB
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
package securebytes
import (
"reflect"
"testing"
)
type testStruct struct {
UserID int
Message string
}
var secret = testStruct{123123123, "secret"}
func encryptDecrypt(t *testing.T, sb *SecureBytes) {
b64, err := sb.EncryptToBase64(secret)
if err != nil {
t.Error(err)
}
var result testStruct
err = sb.DecryptBase64(b64, &result)
if err != nil {
t.Error(err)
}
t.Log(b64)
if !reflect.DeepEqual(result, secret) {
t.Log(result)
t.Error("source and decoded data don't match")
}
}
func TestEncryptDecryptJSON(t *testing.T) {
sb := New(nil, JSONSerializer{})
encryptDecrypt(t, sb)
}
func TestEncryptDecryptGOB(t *testing.T) {
sb := New(nil, GOBSerializer{})
encryptDecrypt(t, sb)
}
func TestEncryptDecryptASN1(t *testing.T) {
sb := New(nil, ASN1Serializer{})
encryptDecrypt(t, sb)
}
func BenchmarkSecureBytesJSON(b *testing.B) {
var b64 string
var result testStruct
sb := New(nil, JSONSerializer{})
for i := 0; i < b.N; i++ {
b64, _ = sb.EncryptToBase64(secret)
sb.DecryptBase64(b64, &result)
}
}
func BenchmarkSecureBytesGOB(b *testing.B) {
var b64 string
var result testStruct
sb := New(nil, GOBSerializer{})
for i := 0; i < b.N; i++ {
b64, _ = sb.EncryptToBase64(secret)
sb.DecryptBase64(b64, &result)
}
}
func BenchmarkSecureBytesASN1(b *testing.B) {
var b64 string
var result testStruct
sb := New(nil, ASN1Serializer{})
for i := 0; i < b.N; i++ {
b64, _ = sb.EncryptToBase64(secret)
sb.DecryptBase64(b64, &result)
}
}