-
Notifications
You must be signed in to change notification settings - Fork 37
/
common_test.go
62 lines (46 loc) · 1.09 KB
/
common_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
package keystore
import (
"crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestZeroing(t *testing.T) {
const tableLength = 20
var table = make([][]byte, tableLength)
for i := range tableLength {
buf := make([]byte, 4096)
_, err := rand.Read(buf)
require.NoError(t, err)
table[i] = buf
}
for _, tt := range table {
zeroing(tt)
for i := range tt {
assert.Equalf(t, uint8(0), tt[i], "fill input with zeros '%v'", tt)
}
}
}
func TestPasswordBytes(t *testing.T) {
type item struct {
input []byte
output []byte
}
const tableLength = 20
var table = make([]item, tableLength)
for i := range tableLength {
input := make([]byte, 1024)
_, err := rand.Read(input)
require.NoError(t, err)
output := make([]byte, len(input)*2)
for j, k := 0, 0; j < len(output); j, k = j+2, k+1 {
output[j] = 0
output[j+1] = input[k]
}
table[i] = item{input: input, output: output}
}
for _, tt := range table {
output := passwordBytes(tt.input)
assert.Equal(t, tt.output, output, "convert password bytes")
}
}