-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargon2id_test.go
55 lines (39 loc) · 1.04 KB
/
argon2id_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
package argon2id
import (
"fmt"
rand2 "math/rand"
"testing"
)
func TestNewArgon2ID(t *testing.T) {
argon2id := NewArgon2ID()
plainTexts := make([]string, 100)
for i := 0; i < 100; i++ {
plainTexts[i] = randomString(int(rand2.Uint32()) % 255)
}
for _, plainText := range plainTexts {
hash, hashErr := argon2id.Hash(plainText)
if hashErr != nil {
t.Errorf("Error producing hash for plaintext %s: %s", plainText, hashErr.Error())
}
res, verErr := argon2id.Verify(plainText, hash)
if verErr != nil {
t.Errorf("Error verifying plainText with hash %s %s: %s", plainText, hash, hashErr.Error())
}
if !res {
t.Errorf("plainText not verified against hash %s %s", plainText, hash)
}
}
}
func TestRandomString(t *testing.T) {
tests := 100
var randomStrings = make(map[string]string)
for i := 0; i < tests; i++ {
rs := randomString(int(rand2.Uint32()) % 255)
randomStrings[rs] = ""
fmt.Println(rs)
}
entries := len(randomStrings)
if entries != tests {
t.Errorf("Tests: %d\t Entries: %d", tests, entries)
}
}