ops = php_hash_fetch_ops(algo, algo_len);
if (!ops) {
- php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
- RETURN_FALSE;
+ zend_throw_error(NULL, "Unknown hashing algorithm: %s", algo);
+ return;
}
else if (!ops->is_crypto) {
- php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
- RETURN_FALSE;
+ zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", algo);
+ return;
}
if (iterations <= 0) {
- php_error_docref(NULL, E_WARNING, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations);
- RETURN_FALSE;
+ zend_throw_error(NULL, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations);
+ return;
}
if (length < 0) {
- php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length);
- RETURN_FALSE;
+ zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length);
+ return;
}
if (salt_len > INT_MAX - 4) {
- php_error_docref(NULL, E_WARNING, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len);
- RETURN_FALSE;
+ zend_throw_error(NULL, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len);
+ return;
}
context = emalloc(ops->context_size);
$salt = 'salt';
echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n";
-var_dump(hash_pbkdf2('foo', $password, $salt, 1));
+try {
+ var_dump(hash_pbkdf2('foo', $password, $salt, 1));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
echo "\n-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --\n";
-var_dump(hash_pbkdf2('crc32', $password, $salt, 1));
+try {
+ var_dump(hash_pbkdf2('crc32', $password, $salt, 1));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n";
-var_dump(hash_pbkdf2('md5', $password, $salt, 0));
-var_dump(hash_pbkdf2('md5', $password, $salt, -1));
+try {
+ var_dump(hash_pbkdf2('md5', $password, $salt, 0));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(hash_pbkdf2('md5', $password, $salt, -1));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
echo "\n-- Testing hash_pbkdf2() function with invalid length --\n";
-var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1));
+try {
+ var_dump(hash_pbkdf2('md5', $password, $salt, 1, -1));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing hash_pbkdf2() : error conditions ***
-- Testing hash_pbkdf2() function with invalid hash algorithm --
-
-Warning: hash_pbkdf2(): Unknown hashing algorithm: foo in %s on line %d
-bool(false)
+Unknown hashing algorithm: foo
-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --
-
-Warning: hash_pbkdf2(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
-bool(false)
+Non-cryptographic hashing algorithm: crc32
-- Testing hash_pbkdf2() function with invalid iterations --
-
-Warning: hash_pbkdf2(): Iterations must be a positive integer: 0 in %s on line %d
-bool(false)
-
-Warning: hash_pbkdf2(): Iterations must be a positive integer: -1 in %s on line %d
-bool(false)
+Iterations must be a positive integer: 0
+Iterations must be a positive integer: -1
-- Testing hash_pbkdf2() function with invalid length --
-
-Warning: hash_pbkdf2(): Length must be greater than or equal to 0: -1 in %s on line %d
-bool(false)
+Length must be greater than or equal to 0: -1
===Done===