-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_test.go
executable file
·48 lines (40 loc) · 1.03 KB
/
crypto_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
package kvod
import (
"reflect"
"testing"
)
func TestEncryptDecrypt(t *testing.T) {
passphrase, _ := GenerateRandom(10)
salt, _ := GenerateRandom(saltSize)
crypto := InitCrypto(string(passphrase), salt)
data, _ := GenerateRandom(100)
encryptedData, _ := crypto.encrypt(data)
decryptedData, _ := crypto.decrypt(encryptedData)
if !reflect.DeepEqual(data, decryptedData) {
t.Error("Encrypt/Decrypt failed")
}
}
func BenchmarkGenerateKey(b *testing.B) {
passphrase := []byte("test")
salt, _ := GenerateRandom(saltSize)
for n := 0; n < b.N; n++ {
generateKey(passphrase, salt)
}
}
func BenchmarkEncrypt(b *testing.B) {
salt, _ := GenerateRandom(saltSize)
crypto := InitCrypto("test", salt)
data, _ := GenerateRandom(100)
for n := 0; n < b.N; n++ {
crypto.encrypt(data)
}
}
func BenchmarkDecrypt(b *testing.B) {
salt, _ := GenerateRandom(saltSize)
crypto := InitCrypto("test", salt)
data, _ := GenerateRandom(100)
encryptedData, _ := crypto.encrypt(data)
for n := 0; n < b.N; n++ {
crypto.decrypt(encryptedData)
}
}