-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecbpass_test.go
More file actions
56 lines (53 loc) · 1.46 KB
/
ecbpass_test.go
File metadata and controls
56 lines (53 loc) · 1.46 KB
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
package main
import (
"encoding/hex"
"fmt"
"strings"
"testing"
)
func Test1(t *testing.T) {
tests := []struct {
password string
salt string
wantPBKDF string
wantHashhint string
}{
{"test", "ecbpass", "BiDY;^Du^s", " 4 F 2"},
{"aaaaa", "google.com", "2djGw;xa7d6", "5 F 3"},
{"12345", "averylonglonglonglonglonglongdomain.com", "2rP>D?I5QKt", "3 2 EF BE2"},
{"averyveryveryveryveryveryverylongpassword", "domain.com", "37Jnqbd`EtO", "3 F4 C"},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("#%d: %v %v", i, tt.password, tt.salt), func(t *testing.T) {
if got := PBKDF2([]byte(tt.password), []byte(tt.salt)); got != tt.wantPBKDF {
t.Errorf("PBKDF2() = %v, want %v", got, tt.wantPBKDF)
}
})
t.Run(fmt.Sprintf("#%v hashhint", i), func(t *testing.T) {
if got := strings.TrimRight(Hashhint([]byte(tt.password)), " "); got != tt.wantHashhint {
t.Errorf("Hashhint() = %v, want %v", got, tt.wantHashhint)
}
})
}
}
func Test_baseStringEnc(t *testing.T) {
tests := []struct {
input []byte
want string
}{
{[]byte{}, "0"},
{[]byte{0x00}, "0"},
{[]byte{0x01}, "1"},
{[]byte{0x02}, "2"},
{[]byte{0x0a}, ":"},
{[]byte{0x0b}, ";"},
// TODO: add more.
}
for _, tt := range tests {
t.Run(hex.EncodeToString(tt.input), func(t *testing.T) {
if got := baseStringEnc(tt.input); got != tt.want {
t.Errorf("baseStringEnc() = %v, want %v", got, tt.want)
}
})
}
}