@@ -3,76 +3,71 @@ Hash: hash_hkdf() function: error conditions
3
3
--FILE--
4
4
<?php
5
5
6
+ error_reporting (E_ALL );
7
+
6
8
/* Prototype : string hkdf ( string $algo , string $ikm [, int $length , string $info = '' , string $salt = '' ] )
7
9
* Description: HMAC-based Key Derivation Function
8
10
* Source code: ext/hash/hash.c
9
11
*/
10
12
13
+ function trycatch_dump (...$ tests ) {
14
+ foreach ($ tests as $ test ) {
15
+ try {
16
+ var_dump ($ test ());
17
+ }
18
+ catch (\Error $ e ) {
19
+ echo '[ ' . get_class ($ e ) . '] ' . $ e ->getMessage () . "\n" ;
20
+ }
21
+ }
22
+ }
23
+
11
24
$ ikm = 'input key material ' ;
12
25
13
26
echo "*** Testing hash_hkdf(): error conditions *** \n" ;
14
27
15
28
echo "\n-- Testing hash_hkdf() function with invalid hash algorithm -- \n" ;
16
- var_dump (hash_hkdf ('foo ' , $ ikm ));
29
+ trycatch_dump (
30
+ fn () => hash_hkdf ('foo ' , $ ikm )
31
+ );
17
32
18
33
echo "\n-- Testing hash_hkdf() function with non-cryptographic hash algorithm -- \n" ;
19
- var_dump (hash_hkdf ('adler32 ' , $ ikm ));
20
- var_dump (hash_hkdf ('crc32 ' , $ ikm ));
21
- var_dump (hash_hkdf ('crc32b ' , $ ikm ));
22
- var_dump (hash_hkdf ('fnv132 ' , $ ikm ));
23
- var_dump (hash_hkdf ('fnv1a32 ' , $ ikm ));
24
- var_dump (hash_hkdf ('fnv164 ' , $ ikm ));
25
- var_dump (hash_hkdf ('fnv1a64 ' , $ ikm ));
26
- var_dump (hash_hkdf ('joaat ' , $ ikm ));
34
+ trycatch_dump (
35
+ fn () => hash_hkdf ('adler32 ' , $ ikm ),
36
+ fn () => hash_hkdf ('crc32 ' , $ ikm ),
37
+ fn () => hash_hkdf ('crc32b ' , $ ikm ),
38
+ fn () => hash_hkdf ('fnv132 ' , $ ikm ),
39
+ fn () => hash_hkdf ('fnv1a32 ' , $ ikm ),
40
+ fn () => hash_hkdf ('fnv164 ' , $ ikm ),
41
+ fn () => hash_hkdf ('fnv1a64 ' , $ ikm ),
42
+ fn () => hash_hkdf ('joaat ' , $ ikm )
43
+ );
27
44
28
45
echo "\n-- Testing hash_hkdf() function with invalid parameters -- \n" ;
29
- var_dump (hash_hkdf ('sha1 ' , '' ));
30
- var_dump (hash_hkdf ('sha1 ' , $ ikm , -1 ));
31
- var_dump (hash_hkdf ('sha1 ' , $ ikm , 20 * 255 + 1 )); // Length can't be more than 255 times the hash digest size
46
+ trycatch_dump (
47
+ fn () => hash_hkdf ('sha1 ' , '' ),
48
+ fn () => hash_hkdf ('sha1 ' , $ ikm , -1 ),
49
+ fn () => hash_hkdf ('sha1 ' , $ ikm , 20 * 255 + 1 ) // Length can't be more than 255 times the hash digest size
50
+ )
32
51
?>
33
52
===Done===
34
- --EXPECTF --
53
+ --EXPECT --
35
54
*** Testing hash_hkdf(): error conditions ***
36
55
37
56
-- Testing hash_hkdf() function with invalid hash algorithm --
38
-
39
- Warning: hash_hkdf(): Unknown hashing algorithm: foo in %s on line %d
40
- bool(false)
57
+ [Error] Unknown hashing algorithm: foo
41
58
42
59
-- Testing hash_hkdf() function with non-cryptographic hash algorithm --
43
-
44
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: adler32 in %s on line %d
45
- bool(false)
46
-
47
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
48
- bool(false)
49
-
50
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: crc32b in %s on line %d
51
- bool(false)
52
-
53
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv132 in %s on line %d
54
- bool(false)
55
-
56
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv1a32 in %s on line %d
57
- bool(false)
58
-
59
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv164 in %s on line %d
60
- bool(false)
61
-
62
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv1a64 in %s on line %d
63
- bool(false)
64
-
65
- Warning: hash_hkdf(): Non-cryptographic hashing algorithm: joaat in %s on line %d
66
- bool(false)
60
+ [Error] Non-cryptographic hashing algorithm: adler32
61
+ [Error] Non-cryptographic hashing algorithm: crc32
62
+ [Error] Non-cryptographic hashing algorithm: crc32b
63
+ [Error] Non-cryptographic hashing algorithm: fnv132
64
+ [Error] Non-cryptographic hashing algorithm: fnv1a32
65
+ [Error] Non-cryptographic hashing algorithm: fnv164
66
+ [Error] Non-cryptographic hashing algorithm: fnv1a64
67
+ [Error] Non-cryptographic hashing algorithm: joaat
67
68
68
69
-- Testing hash_hkdf() function with invalid parameters --
69
-
70
- Warning: hash_hkdf(): Input keying material cannot be empty in %s on line %d
71
- bool(false)
72
-
73
- Warning: hash_hkdf(): Length must be greater than or equal to 0: -1 in %s on line %d
74
- bool(false)
75
-
76
- Warning: hash_hkdf(): Length must be less than or equal to 5100: 5101 in %s on line %d
77
- bool(false)
70
+ [Error] Input keying material cannot be empty
71
+ [Error] Length must be greater than or equal to 0: -1
72
+ [Error] Length must be less than or equal to 5100: 5101
78
73
===Done===
0 commit comments