From 0fe831933fbd33f836200195b935fb6f52b51053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 18 Mar 2020 20:58:37 +0100 Subject: [PATCH 1/3] Promote warnings to exceptions in ext/hash --- ext/hash/hash.c | 12 ++++++------ ext/hash/tests/hash_error.phpt | 12 +++++++----- ext/hash/tests/hash_file_error.phpt | 12 +++++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ext/hash/hash.c b/ext/hash/hash.c index e4f8537676b08..7ff7a312b960d 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -132,13 +132,13 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_ ops = php_hash_fetch_ops(algo); if (!ops) { - php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); - RETURN_FALSE; + zend_argument_value_error(1, "must be a valid hashing algorithm"); + RETURN_THROWS(); } if (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { - php_error_docref(NULL, E_WARNING, "Invalid path"); - RETURN_FALSE; + zend_argument_value_error(1, "must be a valid path"); + RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); if (!stream) { @@ -1065,8 +1065,8 @@ PHP_FUNCTION(mhash_keygen_s2k) bytes = (int)l_bytes; if (bytes <= 0){ - php_error_docref(NULL, E_WARNING, "The byte parameter must be greater than 0"); - RETURN_FALSE; + zend_argument_value_error(4, "must be a greater than 0"); + RETURN_THROWS(); } salt_len = MIN(salt_len, SALT_SIZE); diff --git a/ext/hash/tests/hash_error.phpt b/ext/hash/tests/hash_error.phpt index 8a54831c1a6db..9536110fd69a7 100644 --- a/ext/hash/tests/hash_error.phpt +++ b/ext/hash/tests/hash_error.phpt @@ -11,13 +11,15 @@ Hash: hash() function : error conditions echo "*** Testing hash() : error conditions ***\n"; echo "\n-- Testing hash() function with invalid hash algorithm --\n"; -var_dump(hash('foo', '')); +try { + hash('foo', ''); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} ?> ---EXPECTF-- +--EXPECT-- *** Testing hash() : error conditions *** -- Testing hash() function with invalid hash algorithm -- - -Warning: hash(): Unknown hashing algorithm: foo in %s on line %d -bool(false) +hash(): Argument #1 ($algo) must be a valid hashing algorithm diff --git a/ext/hash/tests/hash_file_error.phpt b/ext/hash/tests/hash_file_error.phpt index eecd2638dad03..2130389a94218 100644 --- a/ext/hash/tests/hash_file_error.phpt +++ b/ext/hash/tests/hash_file_error.phpt @@ -19,10 +19,14 @@ file_put_contents( $filename, 'The quick brown fox jumped over the lazy dog.' ); // hash_file() error tests echo "\n-- Testing hash_file() function with an unknown algorithm --\n"; -var_dump( hash_file( 'foobar', $filename ) ); +try { + hash_file('foobar', $filename); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "\n-- Testing hash_file() function with a non-existent file --\n"; -var_dump( hash_file( 'md5', 'nonexistent.txt' ) ); +var_dump(hash_file('md5', 'nonexistent.txt')); ?> --CLEAN-- @@ -36,9 +40,7 @@ unlink( $filename ); *** Testing hash_file() : error conditions *** -- Testing hash_file() function with an unknown algorithm -- - -Warning: hash_file(): Unknown hashing algorithm: %s in %s on line %d -bool(false) +hash_file(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_file() function with a non-existent file -- From bb28d61eb233292da93392f55fb3142be71c05e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Wed, 18 Mar 2020 20:58:45 +0100 Subject: [PATCH 2/3] Improve error messages of ext/hash --- ext/hash/hash.c | 42 ++++++++++++------------ ext/hash/tests/hash_equals.phpt | 12 +++---- ext/hash/tests/hash_hkdf_edges.phpt | 2 +- ext/hash/tests/hash_hkdf_error.phpt | 24 +++++++------- ext/hash/tests/hash_hmac_error.phpt | 4 +-- ext/hash/tests/hash_hmac_file_error.phpt | 6 ++-- ext/hash/tests/hash_init_error.phpt | 8 ++--- ext/hash/tests/hash_pbkdf2_error.phpt | 10 +++--- 8 files changed, 54 insertions(+), 54 deletions(-) diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 7ff7a312b960d..8b88e7eb525b7 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -255,17 +255,17 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, ops = php_hash_fetch_ops(algo); if (!ops) { - zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a valid hashing algorithm"); RETURN_THROWS(); } else if (!ops->is_crypto) { - zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); RETURN_THROWS(); } if (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { - zend_throw_error(NULL, "Invalid path"); + zend_argument_value_error(2, "must be a valid path"); RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); @@ -361,18 +361,18 @@ PHP_FUNCTION(hash_init) ops = php_hash_fetch_ops(algo); if (!ops) { - zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a valid hashing algorithm"); RETURN_THROWS(); } if (options & PHP_HASH_HMAC) { if (!ops->is_crypto) { - zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(2, "must not request HMAC with a non-cryptographic hashing algorithm"); RETURN_THROWS(); } if (!key || (ZSTR_LEN(key) == 0)) { /* Note: a zero length key is no key at all */ - zend_throw_error(NULL, "HMAC requested without a key"); + zend_argument_value_error(3, "cannot be empty when HMAC is requested"); RETURN_THROWS(); } } @@ -650,27 +650,27 @@ PHP_FUNCTION(hash_hkdf) ops = php_hash_fetch_ops(algo); if (!ops) { - zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a valid hashing algorithm"); RETURN_THROWS(); } if (!ops->is_crypto) { - zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); RETURN_THROWS(); } if (ZSTR_LEN(ikm) == 0) { - zend_throw_error(NULL, "Input keying material cannot be empty"); + zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); } if (length < 0) { - zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); + zend_argument_value_error(3, "must be greater than or equal to 0"); RETURN_THROWS(); } else if (length == 0) { length = ops->digest_size; } else if (length > (zend_long) (ops->digest_size * 255)) { - zend_throw_error(NULL, "Length must be less than or equal to %zd: " ZEND_LONG_FMT, ops->digest_size * 255, length); + zend_argument_value_error(3, "must be less than or equal to %zd", ops->digest_size * 255); RETURN_THROWS(); } @@ -750,26 +750,26 @@ PHP_FUNCTION(hash_pbkdf2) ops = php_hash_fetch_ops(algo); if (!ops) { - zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a valid hashing algorithm"); RETURN_THROWS(); } else if (!ops->is_crypto) { - zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); + zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); RETURN_THROWS(); } - if (iterations <= 0) { - zend_throw_error(NULL, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations); + if (salt_len > INT_MAX - 4) { + zend_argument_value_error(3, "must be less than or equal to INT_MAX - 4 bytes"); RETURN_THROWS(); } - if (length < 0) { - zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); + if (iterations <= 0) { + zend_argument_value_error(4, "must be greater than 0"); RETURN_THROWS(); } - if (salt_len > INT_MAX - 4) { - zend_throw_error(NULL, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len); + if (length < 0) { + zend_argument_value_error(5, "must be greater than or equal to 0"); RETURN_THROWS(); } @@ -875,12 +875,12 @@ PHP_FUNCTION(hash_equals) /* We only allow comparing string to prevent unexpected results. */ if (Z_TYPE_P(known_zval) != IS_STRING) { - zend_type_error("Expected known_string to be a string, %s given", zend_zval_type_name(known_zval)); + zend_argument_type_error(1, "must be of type string, %s given", zend_zval_type_name(known_zval)); RETURN_THROWS(); } if (Z_TYPE_P(user_zval) != IS_STRING) { - zend_type_error("Expected user_string to be a string, %s given", zend_zval_type_name(user_zval)); + zend_argument_type_error(2, "must be of type string, %s given", zend_zval_type_name(user_zval)); RETURN_THROWS(); } diff --git a/ext/hash/tests/hash_equals.phpt b/ext/hash/tests/hash_equals.phpt index 1716d3be6629b..69e23eea0fa38 100644 --- a/ext/hash/tests/hash_equals.phpt +++ b/ext/hash/tests/hash_equals.phpt @@ -39,9 +39,9 @@ bool(false) bool(false) bool(false) bool(true) -[TypeError] Expected known_string to be a string, int given -[TypeError] Expected user_string to be a string, int given -[TypeError] Expected known_string to be a string, int given -[TypeError] Expected known_string to be a string, null given -[TypeError] Expected known_string to be a string, null given -[TypeError] Expected known_string to be a string, null given +[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, int given +[TypeError] hash_equals(): Argument #2 ($user_string) must be of type string, int given +[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, int given +[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given +[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given +[TypeError] hash_equals(): Argument #1 ($known_string) must be of type string, null given diff --git a/ext/hash/tests/hash_hkdf_edges.phpt b/ext/hash/tests/hash_hkdf_edges.phpt index 4a69c7c13419b..dba4ed544b06a 100644 --- a/ext/hash/tests/hash_hkdf_edges.phpt +++ b/ext/hash/tests/hash_hkdf_edges.phpt @@ -31,4 +31,4 @@ Length < digestSize: 98b16391063ece Length % digestSize != 0: 98b16391063ecee006a3ca8ee5776b1e5f Algo name case-sensitivity: true Non-crypto algo name case-sensitivity: -[Error] Non-cryptographic hashing algorithm: jOaAt +[Error] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm diff --git a/ext/hash/tests/hash_hkdf_error.phpt b/ext/hash/tests/hash_hkdf_error.phpt index 411d0637ab0d1..451936fcc4a98 100644 --- a/ext/hash/tests/hash_hkdf_error.phpt +++ b/ext/hash/tests/hash_hkdf_error.phpt @@ -53,19 +53,19 @@ trycatch_dump( *** Testing hash_hkdf(): error conditions *** -- Testing hash_hkdf() function with invalid hash algorithm -- -[Error] Unknown hashing algorithm: foo +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_hkdf() function with non-cryptographic hash algorithm -- -[Error] Non-cryptographic hashing algorithm: adler32 -[Error] Non-cryptographic hashing algorithm: crc32 -[Error] Non-cryptographic hashing algorithm: crc32b -[Error] Non-cryptographic hashing algorithm: fnv132 -[Error] Non-cryptographic hashing algorithm: fnv1a32 -[Error] Non-cryptographic hashing algorithm: fnv164 -[Error] Non-cryptographic hashing algorithm: fnv1a64 -[Error] Non-cryptographic hashing algorithm: joaat +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -- Testing hash_hkdf() function with invalid parameters -- -[Error] Input keying material cannot be empty -[Error] Length must be greater than or equal to 0: -1 -[Error] Length must be less than or equal to 5100: 5101 +[ValueError] hash_hkdf(): Argument #2 ($ikm) cannot be empty +[ValueError] hash_hkdf(): Argument #3 ($length) must be greater than or equal to 0 +[ValueError] hash_hkdf(): Argument #3 ($length) must be less than or equal to 5100 diff --git a/ext/hash/tests/hash_hmac_error.phpt b/ext/hash/tests/hash_hmac_error.phpt index 3b14243fb292d..3b9c4fd79d5a1 100644 --- a/ext/hash/tests/hash_hmac_error.phpt +++ b/ext/hash/tests/hash_hmac_error.phpt @@ -33,7 +33,7 @@ catch (\Error $e) { *** Testing hash_hmac() : error conditions *** -- Testing hash_hmac() function with invalid hash algorithm -- -Unknown hashing algorithm: foo +hash_hmac(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_hmac() function with non-cryptographic hash algorithm -- -Non-cryptographic hashing algorithm: crc32 +hash_hmac(): Argument #1 ($algo) must be a cryptographic hashing algorithm diff --git a/ext/hash/tests/hash_hmac_file_error.phpt b/ext/hash/tests/hash_hmac_file_error.phpt index f23d33569922f..f7da86e2681e2 100644 --- a/ext/hash/tests/hash_hmac_file_error.phpt +++ b/ext/hash/tests/hash_hmac_file_error.phpt @@ -43,10 +43,10 @@ catch (\Error $e) { *** Testing hash() : error conditions *** -- Testing hash_hmac_file() function with invalid hash algorithm -- -Unknown hashing algorithm: foo +hash_hmac_file(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_hmac_file() function with non-cryptographic hash algorithm -- -Non-cryptographic hashing algorithm: crc32 +hash_hmac_file(): Argument #1 ($algo) must be a cryptographic hashing algorithm -- Testing hash_hmac_file() function with bad path -- -Invalid path +hash_hmac_file(): Argument #2 ($data) must be a valid path diff --git a/ext/hash/tests/hash_init_error.phpt b/ext/hash/tests/hash_init_error.phpt index f9d0362dd2b84..b1d3edae82fda 100644 --- a/ext/hash/tests/hash_init_error.phpt +++ b/ext/hash/tests/hash_init_error.phpt @@ -41,11 +41,11 @@ catch (\Error $e) { *** Testing hash_init(): error conditions *** -- Testing hash_init() function with unknown algorithms -- -Unknown hashing algorithm: dummy +hash_init(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms -- -HMAC requested with a non-cryptographic hashing algorithm: crc32 +hash_init(): Argument #2 ($options) must not request HMAC with a non-cryptographic hashing algorithm -- Testing hash_init() function with HASH_HMAC and no key -- -HMAC requested without a key -HMAC requested without a key +hash_init(): Argument #3 ($key) cannot be empty when HMAC is requested +hash_init(): Argument #3 ($key) cannot be empty when HMAC is requested diff --git a/ext/hash/tests/hash_pbkdf2_error.phpt b/ext/hash/tests/hash_pbkdf2_error.phpt index 795dea1ce3169..3fca1fe3dec40 100644 --- a/ext/hash/tests/hash_pbkdf2_error.phpt +++ b/ext/hash/tests/hash_pbkdf2_error.phpt @@ -57,14 +57,14 @@ catch (\Error $e) { *** Testing hash_pbkdf2() : error conditions *** -- Testing hash_pbkdf2() function with invalid hash algorithm -- -Unknown hashing algorithm: foo +hash_pbkdf2(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_pbkdf2() function with non-cryptographic hash algorithm -- -Non-cryptographic hashing algorithm: crc32 +hash_pbkdf2(): Argument #1 ($algo) must be a cryptographic hashing algorithm -- Testing hash_pbkdf2() function with invalid iterations -- -Iterations must be a positive integer: 0 -Iterations must be a positive integer: -1 +hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0 +hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0 -- Testing hash_pbkdf2() function with invalid length -- -Length must be greater than or equal to 0: -1 +hash_pbkdf2(): Argument #5 ($length) must be greater than or equal to 0 From 8eefdc9af2be44eaa682ea424abb738b957a86b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Mon, 23 Mar 2020 16:00:44 +0100 Subject: [PATCH 3/3] Address code review comments --- ext/hash/hash.c | 31 +++++++----------------- ext/hash/tests/hash_hkdf_edges.phpt | 2 +- ext/hash/tests/hash_hkdf_error.phpt | 18 +++++++------- ext/hash/tests/hash_hmac_error.phpt | 4 +-- ext/hash/tests/hash_hmac_file_error.phpt | 6 ++--- ext/hash/tests/hash_init_error.phpt | 2 +- ext/hash/tests/hash_pbkdf2_error.phpt | 4 +-- 7 files changed, 27 insertions(+), 40 deletions(-) diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 8b88e7eb525b7..7f58060158055 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -137,7 +137,7 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_ } if (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { - zend_argument_value_error(1, "must be a valid path"); + zend_argument_type_error(1, "must be a valid path"); RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); @@ -254,18 +254,14 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, } ops = php_hash_fetch_ops(algo); - if (!ops) { - zend_argument_value_error(1, "must be a valid hashing algorithm"); - RETURN_THROWS(); - } - else if (!ops->is_crypto) { - zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); + if (!ops || !ops->is_crypto) { + zend_argument_value_error(1, "must be a valid cryptographic hashing algorithm"); RETURN_THROWS(); } if (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { - zend_argument_value_error(2, "must be a valid path"); + zend_argument_type_error(2, "must be a valid path"); RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); @@ -367,7 +363,7 @@ PHP_FUNCTION(hash_init) if (options & PHP_HASH_HMAC) { if (!ops->is_crypto) { - zend_argument_value_error(2, "must not request HMAC with a non-cryptographic hashing algorithm"); + zend_argument_value_error(1, "must be a cryptographic hashing algorithm if HMAC is requested"); RETURN_THROWS(); } if (!key || (ZSTR_LEN(key) == 0)) { @@ -649,13 +645,8 @@ PHP_FUNCTION(hash_hkdf) } ops = php_hash_fetch_ops(algo); - if (!ops) { - zend_argument_value_error(1, "must be a valid hashing algorithm"); - RETURN_THROWS(); - } - - if (!ops->is_crypto) { - zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); + if (!ops || !ops->is_crypto) { + zend_argument_value_error(1, "must be a valid cryptographic hashing algorithm"); RETURN_THROWS(); } @@ -749,12 +740,8 @@ PHP_FUNCTION(hash_pbkdf2) } ops = php_hash_fetch_ops(algo); - if (!ops) { - zend_argument_value_error(1, "must be a valid hashing algorithm"); - RETURN_THROWS(); - } - else if (!ops->is_crypto) { - zend_argument_value_error(1, "must be a cryptographic hashing algorithm"); + if (!ops || !ops->is_crypto) { + zend_argument_value_error(1, "must be a valid cryptographic hashing algorithm"); RETURN_THROWS(); } diff --git a/ext/hash/tests/hash_hkdf_edges.phpt b/ext/hash/tests/hash_hkdf_edges.phpt index dba4ed544b06a..cee86ae82ead4 100644 --- a/ext/hash/tests/hash_hkdf_edges.phpt +++ b/ext/hash/tests/hash_hkdf_edges.phpt @@ -31,4 +31,4 @@ Length < digestSize: 98b16391063ece Length % digestSize != 0: 98b16391063ecee006a3ca8ee5776b1e5f Algo name case-sensitivity: true Non-crypto algo name case-sensitivity: -[Error] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[Error] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm diff --git a/ext/hash/tests/hash_hkdf_error.phpt b/ext/hash/tests/hash_hkdf_error.phpt index 451936fcc4a98..7ed631251f407 100644 --- a/ext/hash/tests/hash_hkdf_error.phpt +++ b/ext/hash/tests/hash_hkdf_error.phpt @@ -53,17 +53,17 @@ trycatch_dump( *** Testing hash_hkdf(): error conditions *** -- Testing hash_hkdf() function with invalid hash algorithm -- -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_hkdf() function with non-cryptographic hash algorithm -- -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm -[ValueError] hash_hkdf(): Argument #1 ($algo) must be a cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm +[ValueError] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_hkdf() function with invalid parameters -- [ValueError] hash_hkdf(): Argument #2 ($ikm) cannot be empty diff --git a/ext/hash/tests/hash_hmac_error.phpt b/ext/hash/tests/hash_hmac_error.phpt index 3b9c4fd79d5a1..9d303467ef12e 100644 --- a/ext/hash/tests/hash_hmac_error.phpt +++ b/ext/hash/tests/hash_hmac_error.phpt @@ -33,7 +33,7 @@ catch (\Error $e) { *** Testing hash_hmac() : error conditions *** -- Testing hash_hmac() function with invalid hash algorithm -- -hash_hmac(): Argument #1 ($algo) must be a valid hashing algorithm +hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_hmac() function with non-cryptographic hash algorithm -- -hash_hmac(): Argument #1 ($algo) must be a cryptographic hashing algorithm +hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm diff --git a/ext/hash/tests/hash_hmac_file_error.phpt b/ext/hash/tests/hash_hmac_file_error.phpt index f7da86e2681e2..8208c6ebd4fe1 100644 --- a/ext/hash/tests/hash_hmac_file_error.phpt +++ b/ext/hash/tests/hash_hmac_file_error.phpt @@ -34,7 +34,7 @@ echo "\n-- Testing hash_hmac_file() function with bad path --\n"; try { var_dump(hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE)); } -catch (\Error $e) { +catch (TypeError $e) { echo $e->getMessage() . "\n"; } @@ -43,10 +43,10 @@ catch (\Error $e) { *** Testing hash() : error conditions *** -- Testing hash_hmac_file() function with invalid hash algorithm -- -hash_hmac_file(): Argument #1 ($algo) must be a valid hashing algorithm +hash_hmac_file(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_hmac_file() function with non-cryptographic hash algorithm -- -hash_hmac_file(): Argument #1 ($algo) must be a cryptographic hashing algorithm +hash_hmac_file(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_hmac_file() function with bad path -- hash_hmac_file(): Argument #2 ($data) must be a valid path diff --git a/ext/hash/tests/hash_init_error.phpt b/ext/hash/tests/hash_init_error.phpt index b1d3edae82fda..fdea4174d6fc9 100644 --- a/ext/hash/tests/hash_init_error.phpt +++ b/ext/hash/tests/hash_init_error.phpt @@ -44,7 +44,7 @@ catch (\Error $e) { hash_init(): Argument #1 ($algo) must be a valid hashing algorithm -- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms -- -hash_init(): Argument #2 ($options) must not request HMAC with a non-cryptographic hashing algorithm +hash_init(): Argument #1 ($algo) must be a cryptographic hashing algorithm if HMAC is requested -- Testing hash_init() function with HASH_HMAC and no key -- hash_init(): Argument #3 ($key) cannot be empty when HMAC is requested diff --git a/ext/hash/tests/hash_pbkdf2_error.phpt b/ext/hash/tests/hash_pbkdf2_error.phpt index 3fca1fe3dec40..7631eeef90676 100644 --- a/ext/hash/tests/hash_pbkdf2_error.phpt +++ b/ext/hash/tests/hash_pbkdf2_error.phpt @@ -57,10 +57,10 @@ catch (\Error $e) { *** Testing hash_pbkdf2() : error conditions *** -- Testing hash_pbkdf2() function with invalid hash algorithm -- -hash_pbkdf2(): Argument #1 ($algo) must be a valid hashing algorithm +hash_pbkdf2(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_pbkdf2() function with non-cryptographic hash algorithm -- -hash_pbkdf2(): Argument #1 ($algo) must be a cryptographic hashing algorithm +hash_pbkdf2(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm -- Testing hash_pbkdf2() function with invalid iterations -- hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0