-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapi_test.go
50 lines (41 loc) · 985 Bytes
/
api_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
package argon2
import (
"fmt"
"strings"
"testing"
)
var zeros [16]byte
var ones = [8]byte{1, 1, 1, 1, 1, 1, 1, 1}
// Fake salt function for the example
func randomSalt() []byte {
return ones[:8]
}
func ExampleKey() {
pw := []byte("hunter2")
salt := randomSalt()
key, err := Key(pw, salt, 3, 1, 8, 32)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%x", key)
// Output: c5dd631f4e715853e0354326c56f7c3aac983e5d86f7fb02f935899c38690f9e
}
func TestKeyErr(t *testing.T) {
pw := zeros[:]
salt := ones[:]
want := "salt too short"
_, err := Key(pw, salt[:1], 3, 1, 8, 8)
if err == nil {
t.Errorf("got nil error, expected %q", want)
} else if !strings.Contains(err.Error(), want) {
t.Errorf("got %q, expected %q", err, want)
}
want = "invalid par"
_, err = Key(pw, salt, 3, 256, 8, 8)
if err == nil {
t.Errorf("got nil error, expected %q", want)
} else if !strings.Contains(err.Error(), want) {
t.Errorf("got %q, expected %q", err, want)
}
}