-
Notifications
You must be signed in to change notification settings - Fork 27
/
encryption_test.go
51 lines (43 loc) · 1.07 KB
/
encryption_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
/*
* knoxite
* Copyright (c) 2016-2018, Christian Muehlhaeuser <muesli@gmail.com>
*
* For license see LICENSE
*/
package knoxite
import (
"testing"
)
func TestEncryption(t *testing.T) {
testPassword := "this_is_a_password"
b := []byte("1234567890")
epipe, err := NewEncodingPipeline(CompressionNone, EncryptionAES, testPassword)
if err != nil {
t.Error(err)
}
be, err := epipe.Process(b)
if err != nil {
t.Error(err)
}
dpipe, err := NewDecodingPipeline(CompressionNone, EncryptionAES, testPassword)
if err != nil {
t.Error(err)
}
bd, err := dpipe.Process(be)
if err != nil {
t.Error(err)
}
if string(b) != string(bd) {
t.Error("Data mismatch after encryption & decryption cycle.")
}
}
func TestEmptyPassword(t *testing.T) {
_, err := NewEncodingPipeline(CompressionNone, EncryptionAES, "")
if err != ErrInvalidPassword {
t.Errorf("Expected %v, got %v", ErrInvalidPassword, err)
}
_, err = NewDecodingPipeline(CompressionNone, EncryptionAES, "")
if err != ErrInvalidPassword {
t.Errorf("Expected %v, got %v", ErrInvalidPassword, err)
}
}