-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys_test.go
60 lines (52 loc) · 1.57 KB
/
keys_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
package nigori
import (
"encoding/base64"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewKeys(t *testing.T) {
tests := []struct {
name string
password string
methodOption keyDerivationMethodOption
expectedUserKey string
expectedEncKey string
expectedMacKey string
hasError bool
}{
{
name: "derivation using pbkdf2",
password: "CAMSEM3y43hLmgd9Zr8e0U7YsioaIJTpcvWg+uX00KlEOAdJuLlKqGen1P0agzDUVV9fdlqK",
methodOption: WithPbkdf2HMACSHA1_1003(),
expectedUserKey: "rZ39BnGk649CrKdF8mJ8Dg==",
expectedEncKey: "4+79zzoztaNSHeb2RVxNPA==",
expectedMacKey: "reTRBk/e4LtVdRc3Erp5kg==",
},
{
name: "derivation using scrypt",
password: "hunter2",
methodOption: WithScrypt8192_8_11("alpensalz"),
expectedUserKey: "AAAAAAAAAAAAAAAAAAAAAA==",
expectedEncKey: "iqc14AkTOaXlHaOz3Rsyig==",
expectedMacKey: "p+c2EZaN/SvKWzOCrtRRug==",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
keys, err := NewKeys(NewDerivationParams(test.methodOption), test.password)
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
encoder := base64.StdEncoding
userkey := encoder.EncodeToString(keys.UserKey)
mackey := encoder.EncodeToString(keys.MacKey)
enckey := encoder.EncodeToString(keys.EncryptionKey)
assert.Equal(t, test.expectedUserKey, userkey)
assert.Equal(t, test.expectedMacKey, mackey)
assert.Equal(t, test.expectedEncKey, enckey)
})
}
}