@@ -4,30 +4,48 @@ Hash: hash_init() function - errors test
4
4
<?php
5
5
echo "*** Testing hash_init(): error conditions *** \n" ;
6
6
7
- echo "-- Testing hash_init() function with unknown algorithms -- \n" ;
8
- var_dump (hash_init ('dummy ' ));
7
+ echo "\n-- Testing hash_init() function with unknown algorithms -- \n" ;
8
+ try {
9
+ var_dump (hash_init ('dummy ' ));
10
+ }
11
+ catch (\Error $ e ) {
12
+ echo $ e ->getMessage () . "\n" ;
13
+ }
14
+
15
+ echo "\n-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms -- \n" ;
16
+ try {
17
+ var_dump (hash_init ('crc32 ' , HASH_HMAC ));
18
+ }
19
+ catch (\Error $ e ) {
20
+ echo $ e ->getMessage () . "\n" ;
21
+ }
22
+
23
+ echo "\n-- Testing hash_init() function with HASH_HMAC and no key -- \n" ;
24
+ try {
25
+ var_dump (hash_init ('md5 ' , HASH_HMAC ));
26
+ }
27
+ catch (\Error $ e ) {
28
+ echo $ e ->getMessage () . "\n" ;
29
+ }
30
+
31
+ try {
32
+ var_dump (hash_init ('md5 ' , HASH_HMAC , null ));
33
+ }
34
+ catch (\Error $ e ) {
35
+ echo $ e ->getMessage () . "\n" ;
36
+ }
9
37
10
- echo "-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms -- \n" ;
11
- var_dump (hash_init ('crc32 ' , HASH_HMAC ));
12
38
13
- echo "-- Testing hash_init() function with HASH_HMAC and no key -- \n" ;
14
- var_dump (hash_init ('md5 ' , HASH_HMAC ));
15
- var_dump (hash_init ('md5 ' , HASH_HMAC , null ));
16
39
?>
17
- --EXPECTF --
40
+ --EXPECT --
18
41
*** Testing hash_init(): error conditions ***
42
+
19
43
-- Testing hash_init() function with unknown algorithms --
44
+ Unknown hashing algorithm: dummy
20
45
21
- Warning: hash_init(): Unknown hashing algorithm: dummy in %s on line %d
22
- bool(false)
23
46
-- Testing hash_init() function with HASH_HMAC and non-cryptographic algorithms --
47
+ HMAC requested with a non-cryptographic hashing algorithm: crc32
24
48
25
- Warning: hash_init(): HMAC requested with a non-cryptographic hashing algorithm: crc32 in %s on line %d
26
- bool(false)
27
49
-- Testing hash_init() function with HASH_HMAC and no key --
28
-
29
- Warning: hash_init(): HMAC requested without a key %s on line %d
30
- bool(false)
31
-
32
- Warning: hash_init(): HMAC requested without a key %s on line %d
33
- bool(false)
50
+ HMAC requested without a key
51
+ HMAC requested without a key
0 commit comments