-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex_test.go
70 lines (56 loc) · 1.39 KB
/
index_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
package aesf
import (
"bytes"
"io"
"testing"
"github.com/dchest/uniuri"
)
var (
TestPwd = "loremlorem"
TestText = []byte("hello world")
)
func test(pwd string, text []byte, t *testing.T) {
testSaltSizel, _ := calSaltSize(len(pwd))
testFullSize := len(text) + testSaltSizel + PwdVerifierSize + SignatureKeySize
aesf, err := New(TestPwd)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
var cipher bytes.Buffer
w, err := aesf.Encrypt(&cipher)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
w.Write(text)
err = w.Close()
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if cipher.Len() != testFullSize {
t.Errorf("Unexpected encrypted data size %d, expect %d", cipher.Len(), testFullSize)
}
var plain bytes.Buffer
dr, err := aesf.Decrypt(&cipher)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
_, err = io.Copy(&plain, dr)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if err = dr.Close(); err != nil {
t.Errorf("Unexpected error: %s", err)
}
if !bytes.Equal(text, plain.Bytes()) {
t.Errorf("Unexpected decrypted data %d, expect %d", plain.Len(), len(text))
}
}
func TestAesf(t *testing.T) {
test(TestPwd, TestText, t)
}
func TestAESfMultipleText(t *testing.T) {
test(TestPwd+TestPwd, []byte(uniuri.NewLen(1536)), t)
}
func TestAESfLongText(t *testing.T) {
test(TestPwd+TestPwd, []byte(uniuri.NewLen(100536)), t)
}