1--TEST--
2Hash: Test hash_pbkdf2() function : error functionality
3--FILE--
4<?php
5
6/* Generate a PBKDF2 hash of the given password and salt
7Returns lowercase hexbits by default */
8
9echo "*** Testing hash_pbkdf2() : error conditions ***\n";
10
11$password = 'password';
12$salt = 'salt';
13
14echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n";
15try {
16    var_dump(hash_pbkdf2('foo', $password, $salt, 1));
17}
18catch (\Error $e) {
19    echo $e->getMessage() . "\n";
20}
21
22
23echo "\n-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --\n";
24try {
25    var_dump(hash_pbkdf2('crc32', $password, $salt, 1));
26}
27catch (\Error $e) {
28    echo $e->getMessage() . "\n";
29}
30
31echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n";
32try {
33    var_dump(hash_pbkdf2('md5', $password, $salt, 0));
34}
35catch (\Error $e) {
36    echo $e->getMessage() . "\n";
37}
38
39try {
40    var_dump(hash_pbkdf2('md5', $password, $salt, -1));
41}
42catch (\Error $e) {
43    echo $e->getMessage() . "\n";
44}
45
46echo "\n-- Testing hash_pbkdf2() function with invalid length --\n";
47try {
48    var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1));
49}
50catch (\Error $e) {
51    echo $e->getMessage() . "\n";
52}
53
54?>
55--EXPECT--
56*** Testing hash_pbkdf2() : error conditions ***
57
58-- Testing hash_pbkdf2() function with invalid hash algorithm --
59hash_pbkdf2(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm
60
61-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --
62hash_pbkdf2(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm
63
64-- Testing hash_pbkdf2() function with invalid iterations --
65hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0
66hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0
67
68-- Testing hash_pbkdf2() function with invalid length --
69hash_pbkdf2(): Argument #5 ($length) must be greater than or equal to 0
70