forked from edwardwc/better-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_test.go
53 lines (41 loc) · 949 Bytes
/
io_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
package badgers3
import (
"bytes"
"io/ioutil"
"testing"
)
func TestEncryptDecrypt(t *testing.T) {
secret := []byte("12345678123456781234567812345678")
var sbuf [32]byte
copy(sbuf[:], secret)
sb := SecretBoxIO{
SecretKey: sbuf,
}
msg := []byte("This is a very important message that shall be encrypted...")
r := sb.ByteReader(msg)
buf, err := ioutil.ReadAll(r)
if err != nil {
t.Errorf("encrypting failed: %v", err)
}
w := bytes.NewReader(buf)
wb := sb.WrapReader(w)
buf, err = ioutil.ReadAll(wb)
if err != nil {
t.Errorf("decrypting failed: %v", err)
}
if string(buf) != string(msg) {
t.Errorf("did not decrypt, got: %s", buf)
}
}
func TestIOWrap(t *testing.T) {
empty := bytes.NewReader(nil)
sb := SecretBoxIO{}
wr := sb.WrapReader(empty)
buf, err := ioutil.ReadAll(wr)
if err != nil {
t.Errorf("reading failed: %s", err)
}
if len(buf) != 0 {
t.Errorf("Buffer should be empty, got: %v", buf)
}
}