@@ -255,17 +255,17 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
255
255
256
256
ops = php_hash_fetch_ops (algo );
257
257
if (!ops ) {
258
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
258
+ zend_argument_value_error ( 1 , "must be a valid hashing algorithm" );
259
259
RETURN_THROWS ();
260
260
}
261
261
else if (!ops -> is_crypto ) {
262
- zend_throw_error ( NULL , "Non- cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
262
+ zend_argument_value_error ( 1 , "must be a cryptographic hashing algorithm" );
263
263
RETURN_THROWS ();
264
264
}
265
265
266
266
if (isfilename ) {
267
267
if (CHECK_NULL_PATH (data , data_len )) {
268
- zend_throw_error ( NULL , "Invalid path" );
268
+ zend_argument_value_error ( 2 , "must be a valid path" );
269
269
RETURN_THROWS ();
270
270
}
271
271
stream = php_stream_open_wrapper_ex (data , "rb" , REPORT_ERRORS , NULL , FG (default_context ));
@@ -361,18 +361,18 @@ PHP_FUNCTION(hash_init)
361
361
362
362
ops = php_hash_fetch_ops (algo );
363
363
if (!ops ) {
364
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
364
+ zend_argument_value_error ( 1 , "must be a valid hashing algorithm" );
365
365
RETURN_THROWS ();
366
366
}
367
367
368
368
if (options & PHP_HASH_HMAC ) {
369
369
if (!ops -> is_crypto ) {
370
- zend_throw_error ( NULL , "HMAC requested with a non-cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
370
+ zend_argument_value_error ( 2 , "must not request HMAC with a non-cryptographic hashing algorithm" );
371
371
RETURN_THROWS ();
372
372
}
373
373
if (!key || (ZSTR_LEN (key ) == 0 )) {
374
374
/* Note: a zero length key is no key at all */
375
- zend_throw_error ( NULL , "HMAC requested without a key " );
375
+ zend_argument_value_error ( 3 , "cannot be empty when HMAC is requested " );
376
376
RETURN_THROWS ();
377
377
}
378
378
}
@@ -650,27 +650,27 @@ PHP_FUNCTION(hash_hkdf)
650
650
651
651
ops = php_hash_fetch_ops (algo );
652
652
if (!ops ) {
653
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
653
+ zend_argument_value_error ( 1 , "must be a valid hashing algorithm" );
654
654
RETURN_THROWS ();
655
655
}
656
656
657
657
if (!ops -> is_crypto ) {
658
- zend_throw_error ( NULL , "Non- cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
658
+ zend_argument_value_error ( 1 , "must be a cryptographic hashing algorithm" );
659
659
RETURN_THROWS ();
660
660
}
661
661
662
662
if (ZSTR_LEN (ikm ) == 0 ) {
663
- zend_throw_error ( NULL , "Input keying material cannot be empty" );
663
+ zend_argument_value_error ( 2 , "cannot be empty" );
664
664
RETURN_THROWS ();
665
665
}
666
666
667
667
if (length < 0 ) {
668
- zend_throw_error ( NULL , "Length must be greater than or equal to 0: " ZEND_LONG_FMT , length );
668
+ zend_argument_value_error ( 3 , "must be greater than or equal to 0" );
669
669
RETURN_THROWS ();
670
670
} else if (length == 0 ) {
671
671
length = ops -> digest_size ;
672
672
} else if (length > (zend_long ) (ops -> digest_size * 255 )) {
673
- zend_throw_error ( NULL , "Length must be less than or equal to %zd: " ZEND_LONG_FMT , ops -> digest_size * 255 , length );
673
+ zend_argument_value_error ( 3 , "must be less than or equal to %zd" , ops -> digest_size * 255 );
674
674
RETURN_THROWS ();
675
675
}
676
676
@@ -750,26 +750,26 @@ PHP_FUNCTION(hash_pbkdf2)
750
750
751
751
ops = php_hash_fetch_ops (algo );
752
752
if (!ops ) {
753
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
753
+ zend_argument_value_error ( 1 , "must be a valid hashing algorithm" );
754
754
RETURN_THROWS ();
755
755
}
756
756
else if (!ops -> is_crypto ) {
757
- zend_throw_error ( NULL , "Non- cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
757
+ zend_argument_value_error ( 1 , "must be a cryptographic hashing algorithm" );
758
758
RETURN_THROWS ();
759
759
}
760
760
761
- if (iterations <= 0 ) {
762
- zend_throw_error ( NULL , "Iterations must be a positive integer: " ZEND_LONG_FMT , iterations );
761
+ if (salt_len > INT_MAX - 4 ) {
762
+ zend_argument_value_error ( 3 , "must be less than or equal to INT_MAX - 4 bytes" );
763
763
RETURN_THROWS ();
764
764
}
765
765
766
- if (length < 0 ) {
767
- zend_throw_error ( NULL , "Length must be greater than or equal to 0: " ZEND_LONG_FMT , length );
766
+ if (iterations <= 0 ) {
767
+ zend_argument_value_error ( 4 , "must be greater than 0" );
768
768
RETURN_THROWS ();
769
769
}
770
770
771
- if (salt_len > INT_MAX - 4 ) {
772
- zend_throw_error ( NULL , "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied" , salt_len );
771
+ if (length < 0 ) {
772
+ zend_argument_value_error ( 5 , "must be greater than or equal to 0" );
773
773
RETURN_THROWS ();
774
774
}
775
775
@@ -875,12 +875,12 @@ PHP_FUNCTION(hash_equals)
875
875
876
876
/* We only allow comparing string to prevent unexpected results. */
877
877
if (Z_TYPE_P (known_zval ) != IS_STRING ) {
878
- zend_type_error ( "Expected known_string to be a string, %s given" , zend_zval_type_name (known_zval ));
878
+ zend_argument_type_error ( 1 , "must be of type string, %s given" , zend_zval_type_name (known_zval ));
879
879
RETURN_THROWS ();
880
880
}
881
881
882
882
if (Z_TYPE_P (user_zval ) != IS_STRING ) {
883
- zend_type_error ( "Expected user_string to be a string, %s given" , zend_zval_type_name (user_zval ));
883
+ zend_argument_type_error ( 2 , "must be of type string, %s given" , zend_zval_type_name (user_zval ));
884
884
RETURN_THROWS ();
885
885
}
886
886
0 commit comments