forked from pavlo-v-chernykh/keystore-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
58 lines (53 loc) · 1.23 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
package keystore
import (
"crypto/rand"
"reflect"
"testing"
)
func TestZeroing(t *testing.T) {
type zeroingItem struct {
input []byte
}
type zeroingTable []zeroingItem
var table zeroingTable
for i := 0; i < 20; i++ {
buf := make([]byte, 4096)
if _, err := rand.Read(buf); err != nil {
t.Errorf("read random bytes: %v", err)
}
table = append(table, zeroingItem{input: buf})
}
for _, tt := range table {
zeroing(tt.input)
for i := range tt.input {
if tt.input[i] != 0 {
t.Errorf("fill input with zeros '%v'", tt.input)
}
}
}
}
func TestPasswordBytes(t *testing.T) {
type passwordBytesItem struct {
input []byte
output []byte
}
var table []passwordBytesItem
for i := 0; i < 20; i++ {
input := make([]byte, 1024)
if _, err := rand.Read(input); err != nil {
t.Errorf("read random bytes: %v", 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 = append(table, passwordBytesItem{input: input, output: output})
}
for _, tt := range table {
output := passwordBytes(tt.input)
if !reflect.DeepEqual(output, tt.output) {
t.Errorf("convert password bytes '%v', '%v'", output, tt.output)
}
}
}