1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 var saltedTests = []struct {
17 {"hello", "10295ac1"},
18 {"world", "ac587a5e"},
20 {"bar", "bd8aac6b9ea9cae04eae6a91c6133b58b5d9a61c14f355516ed9370456"},
22 {"xxxxxxxxxxxxxxxxxxxxxxx", "e00d7b45"},
25 func TestSalted(t *testing.T) {
27 salt := [4]byte{1, 2, 3, 4}
29 for i, test := range saltedTests {
30 expected, _ := hex.DecodeString(test.out)
31 out := make([]byte, len(expected))
32 Salted(out, h, []byte(test.in), salt[:])
33 if !bytes.Equal(expected, out) {
34 t.Errorf("#%d, got: %x want: %x", i, out, expected)
40 var iteratedTests = []struct {
43 {"hello", "83126105"},
44 {"world", "6fa317f9"},
46 {"bar", "2af5a99b54f093789fd657f19bd245af7604d0f6ae06f66602a46a08ae"},
48 {"xxxxxxxxxxxxxxxxxxxxxxx", "18955174"},
51 func TestIterated(t *testing.T) {
53 salt := [4]byte{4, 3, 2, 1}
55 for i, test := range iteratedTests {
56 expected, _ := hex.DecodeString(test.out)
57 out := make([]byte, len(expected))
58 Iterated(out, h, []byte(test.in), salt[:], 31)
59 if !bytes.Equal(expected, out) {
60 t.Errorf("#%d, got: %x want: %x", i, out, expected)
66 var parseTests = []struct {
69 /* Simple with SHA1 */
70 {"0102", "hello", "aaf4c61d"},
71 /* Salted with SHA1 */
72 {"02020102030405060708", "hello", "f4f7d67e"},
73 /* Iterated with SHA1 */
74 {"03020102030405060708f1", "hello", "f2a57b7c"},
77 func TestParse(t *testing.T) {
78 for i, test := range parseTests {
79 spec, _ := hex.DecodeString(test.spec)
80 buf := bytes.NewBuffer(spec)
83 t.Errorf("%d: Parse returned error: %s", i, err)
87 expected, _ := hex.DecodeString(test.out)
88 out := make([]byte, len(expected))
89 f(out, []byte(test.in))
90 if !bytes.Equal(out, expected) {
91 t.Errorf("%d: output got: %x want: %x", i, out, expected)