ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo));
if (!ops) {
- php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
- RETURN_FALSE;
+ zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
+ return;
}
if (options & PHP_HASH_HMAC) {
if (!ops->is_crypto) {
- php_error_docref(NULL, E_WARNING, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
- RETURN_FALSE;
+ zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
+ return;
}
if (!key || (ZSTR_LEN(key) == 0)) {
/* Note: a zero length key is no key at all */
- php_error_docref(NULL, E_WARNING, "HMAC requested without a key");
- RETURN_FALSE;
+ zend_throw_error(NULL, "HMAC requested without a key");
+ return;
}
}
<?php
echo "*** Testing hash_init(): error conditions ***\n";
-echo "-- Testing hash_init() function with unknown algorithms --\n";
-var_dump(hash_init('dummy'));
+echo "\n-- Testing hash_init() function with unknown algorithms --\n";
+try {
+ var_dump(hash_init('dummy'));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+echo "\n-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n";
+try {
+ var_dump(hash_init('crc32', HASH_HMAC));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+echo "\n-- Testing hash_init() function with HASH_HMAC and no key --\n";
+try {
+ var_dump(hash_init('md5', HASH_HMAC));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
+
+try {
+ var_dump(hash_init('md5', HASH_HMAC, null));
+}
+catch (\Error $e) {
+ echo $e->getMessage() . "\n";
+}
-echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --\n";
-var_dump(hash_init('crc32', HASH_HMAC));
-echo "-- Testing hash_init() function with HASH_HMAC and no key --\n";
-var_dump(hash_init('md5', HASH_HMAC));
-var_dump(hash_init('md5', HASH_HMAC, null));
?>
---EXPECTF--
+--EXPECT--
*** Testing hash_init(): error conditions ***
+
-- Testing hash_init() function with unknown algorithms --
+Unknown hashing algorithm: dummy
-Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d
-bool(false)
-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --
+HMAC requested with a non-cryptographic hashing algorithm: crc32
-Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on line %d
-bool(false)
-- Testing hash_init() function with HASH_HMAC and no key --
-
-Warning: hash_init(): HMAC requested without a key %s on line %d
-bool(false)
-
-Warning: hash_init(): HMAC requested without a key %s on line %d
-bool(false)
+HMAC requested without a key
+HMAC requested without a key