diff options
author | EuAndreh <eu@euandre.org> | 2024-07-15 18:09:22 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-07-15 18:09:22 -0300 |
commit | 3d1115fd2e44e83a34f115380d33728d6aaec6bc (patch) | |
tree | a51768e58e01106a224a11a2fb7d4016d773cc36 /tests | |
parent | Inline gobang package code (diff) | |
download | papod-3d1115fd2e44e83a34f115380d33728d6aaec6bc.tar.gz papod-3d1115fd2e44e83a34f115380d33728d6aaec6bc.tar.xz |
src/lib.go, tests/lib_test.go: Tweak indentation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib_test.go | 107 |
1 files changed, 66 insertions, 41 deletions
diff --git a/tests/lib_test.go b/tests/lib_test.go index 2a27ae9..2e872ec 100644 --- a/tests/lib_test.go +++ b/tests/lib_test.go @@ -27,6 +27,12 @@ func errorIf(t *testing.T, err error) { } } +func errorIfNotI(t *testing.T, i int, err error) { + if err == nil { + t.Errorf("Expected error, got nil (i = %d)\n", i) + } +} + func assertEqualI(t *testing.T, i int, given any, expected any) { if !reflect.DeepEqual(given, expected) { t.Errorf("given != expected (i = %d)\n", i) @@ -108,17 +114,19 @@ var sha1TestVectors = []pbkdfTestVector { 0x65, 0xa4, 0x29, 0xc1, }, }, - // // This one takes too long - // { - // "password", - // "salt", - // 16777216, - // []byte { - // 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, - // 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c, - // 0x26, 0x34, 0xe9, 0x84, - // }, - // }, + /* + // This one takes too long + { + "password", + "salt", + 16777216, + []byte { + 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, + 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c, + 0x26, 0x34, 0xe9, 0x84, + }, + }, + */ { "passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", @@ -196,12 +204,21 @@ var sha256TestVectors = []pbkdfTestVector { }, } -func testHash(t *testing.T, h func() hash.Hash, hashName string, vectors []pbkdfTestVector) { +func testHash( + t *testing.T, + h func() hash.Hash, + hashName string, + vectors []pbkdfTestVector, +) { for i, v := range vectors { - o := papod.PBKDF2Key([]byte(v.password), []byte(v.salt), v.iter, len(v.output), h) - if !bytes.Equal(o, v.output) { - t.Errorf("%s %d: expected %x, got %x", hashName, i, v.output, o) - } + o := papod.PBKDF2Key( + []byte(v.password), + []byte(v.salt), + v.iter, + len(v.output), + h, + ) + assertEqualI(t, i, v.output, o) } } @@ -314,21 +331,21 @@ var good = []scryptTestVector { }, }, /* - // Disabled: needs 1 GiB RAM and takes too long for a simple test. - { - "pleaseletmein", "SodiumChloride", - 1048576, 8, 1, - []byte{ - 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae, 0xad, - 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81, 0xec, 0x56, - 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d, 0xab, 0xe5, 0xee, - 0x98, 0x20, 0xad, 0xaa, 0x47, 0x8e, 0x56, 0xfd, 0x8f, - 0x4b, 0xa5, 0xd0, 0x9f, 0xfa, 0x1c, 0x6d, 0x92, 0x7c, - 0x40, 0xf4, 0xc3, 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, - 0x52, 0xfb, 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, - 0xa4, - }, + // Disabled: needs 1 GiB RAM and takes too long for a simple test. + { + "pleaseletmein", "SodiumChloride", + 1048576, 8, 1, + []byte{ + 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae, 0xad, + 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81, 0xec, 0x56, + 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d, 0xab, 0xe5, 0xee, + 0x98, 0x20, 0xad, 0xaa, 0x47, 0x8e, 0x56, 0xfd, 0x8f, + 0x4b, 0xa5, 0xd0, 0x9f, 0xfa, 0x1c, 0x6d, 0x92, 0x7c, + 0x40, 0xf4, 0xc3, 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, + 0x52, 0xfb, 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, + 0xa4, }, + }, */ } @@ -343,19 +360,27 @@ var bad = []scryptTestVector { func TestKey(t *testing.T) { for i, v := range good { - k, err := papod.Scrypt([]byte(v.password), []byte(v.salt), v.N, v.r, v.p, len(v.output)) - if err != nil { - t.Errorf("%d: got unexpected error: %s", i, err) - } - if !bytes.Equal(k, v.output) { - t.Errorf("%d: expected %x, got %x", i, v.output, k) - } + k, err := papod.Scrypt( + []byte(v.password), + []byte(v.salt), + v.N, + v.r, + v.p, + len(v.output), + ) + errorIf(t, err) + assertEqualI(t, i, v.output, k) } for i, v := range bad { - _, err := papod.Scrypt([]byte(v.password), []byte(v.salt), v.N, v.r, v.p, 32) - if err == nil { - t.Errorf("%d: expected error, got nil", i) - } + _, err := papod.Scrypt( + []byte(v.password), + []byte(v.salt), + v.N, + v.r, + v.p, + 32, + ) + errorIfNotI(t, i, err) } } |