@@ -137,7 +137,7 @@ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_
137
137
}
138
138
if (isfilename ) {
139
139
if (CHECK_NULL_PATH (data , data_len )) {
140
- zend_argument_value_error (1 , "must be a valid path" );
140
+ zend_argument_type_error (1 , "must be a valid path" );
141
141
RETURN_THROWS ();
142
142
}
143
143
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,
254
254
}
255
255
256
256
ops = php_hash_fetch_ops (algo );
257
- if (!ops ) {
258
- zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL (algo ));
259
- RETURN_THROWS ();
260
- }
261
- else if (!ops -> is_crypto ) {
262
- zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , ZSTR_VAL (algo ));
257
+ if (!ops || !ops -> is_crypto ) {
258
+ zend_argument_value_error (1 , "must be a valid cryptographic hashing algorithm" );
263
259
RETURN_THROWS ();
264
260
}
265
261
266
262
if (isfilename ) {
267
263
if (CHECK_NULL_PATH (data , data_len )) {
268
- zend_throw_error ( NULL , "Invalid path" );
264
+ zend_argument_type_error ( 2 , "must be a valid path" );
269
265
RETURN_THROWS ();
270
266
}
271
267
stream = php_stream_open_wrapper_ex (data , "rb" , REPORT_ERRORS , NULL , FG (default_context ));
@@ -361,18 +357,18 @@ PHP_FUNCTION(hash_init)
361
357
362
358
ops = php_hash_fetch_ops (algo );
363
359
if (!ops ) {
364
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
360
+ zend_argument_value_error ( 1 , "must be a valid hashing algorithm" );
365
361
RETURN_THROWS ();
366
362
}
367
363
368
364
if (options & PHP_HASH_HMAC ) {
369
365
if (!ops -> is_crypto ) {
370
- zend_throw_error ( NULL , "HMAC requested with a non- cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
366
+ zend_argument_value_error ( 1 , "must be a cryptographic hashing algorithm if HMAC is requested" );
371
367
RETURN_THROWS ();
372
368
}
373
369
if (!key || (ZSTR_LEN (key ) == 0 )) {
374
370
/* Note: a zero length key is no key at all */
375
- zend_throw_error ( NULL , "HMAC requested without a key " );
371
+ zend_argument_value_error ( 3 , "cannot be empty when HMAC is requested " );
376
372
RETURN_THROWS ();
377
373
}
378
374
}
@@ -649,28 +645,23 @@ PHP_FUNCTION(hash_hkdf)
649
645
}
650
646
651
647
ops = php_hash_fetch_ops (algo );
652
- if (!ops ) {
653
- zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL (algo ));
654
- RETURN_THROWS ();
655
- }
656
-
657
- if (!ops -> is_crypto ) {
658
- zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , ZSTR_VAL (algo ));
648
+ if (!ops || !ops -> is_crypto ) {
649
+ zend_argument_value_error (1 , "must be a valid cryptographic hashing algorithm" );
659
650
RETURN_THROWS ();
660
651
}
661
652
662
653
if (ZSTR_LEN (ikm ) == 0 ) {
663
- zend_throw_error ( NULL , "Input keying material cannot be empty" );
654
+ zend_argument_value_error ( 2 , "cannot be empty" );
664
655
RETURN_THROWS ();
665
656
}
666
657
667
658
if (length < 0 ) {
668
- zend_throw_error ( NULL , "Length must be greater than or equal to 0: " ZEND_LONG_FMT , length );
659
+ zend_argument_value_error ( 3 , "must be greater than or equal to 0" );
669
660
RETURN_THROWS ();
670
661
} else if (length == 0 ) {
671
662
length = ops -> digest_size ;
672
663
} 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 );
664
+ zend_argument_value_error ( 3 , "must be less than or equal to %zd" , ops -> digest_size * 255 );
674
665
RETURN_THROWS ();
675
666
}
676
667
@@ -749,27 +740,23 @@ PHP_FUNCTION(hash_pbkdf2)
749
740
}
750
741
751
742
ops = php_hash_fetch_ops (algo );
752
- if (!ops ) {
753
- zend_throw_error ( NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
743
+ if (!ops || ! ops -> is_crypto ) {
744
+ zend_argument_value_error ( 1 , "must be a valid cryptographic hashing algorithm" );
754
745
RETURN_THROWS ();
755
746
}
756
- else if (!ops -> is_crypto ) {
757
- zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , ZSTR_VAL (algo ));
747
+
748
+ if (salt_len > INT_MAX - 4 ) {
749
+ zend_argument_value_error (3 , "must be less than or equal to INT_MAX - 4 bytes" );
758
750
RETURN_THROWS ();
759
751
}
760
752
761
753
if (iterations <= 0 ) {
762
- zend_throw_error ( NULL , "Iterations must be a positive integer: " ZEND_LONG_FMT , iterations );
754
+ zend_argument_value_error ( 4 , "must be greater than 0" );
763
755
RETURN_THROWS ();
764
756
}
765
757
766
758
if (length < 0 ) {
767
- zend_throw_error (NULL , "Length must be greater than or equal to 0: " ZEND_LONG_FMT , length );
768
- RETURN_THROWS ();
769
- }
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 );
759
+ zend_argument_value_error (5 , "must be greater than or equal to 0" );
773
760
RETURN_THROWS ();
774
761
}
775
762
@@ -875,12 +862,12 @@ PHP_FUNCTION(hash_equals)
875
862
876
863
/* We only allow comparing string to prevent unexpected results. */
877
864
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 ));
865
+ zend_argument_type_error ( 1 , "must be of type string, %s given" , zend_zval_type_name (known_zval ));
879
866
RETURN_THROWS ();
880
867
}
881
868
882
869
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 ));
870
+ zend_argument_type_error ( 2 , "must be of type string, %s given" , zend_zval_type_name (user_zval ));
884
871
RETURN_THROWS ();
885
872
}
886
873
0 commit comments