1--TEST--
2Hash: hash_hmac_file() function : basic functionality
3--FILE--
4<?php
5
6/* Prototype  : string hash_hmac_file ( string algo, string filename, string key [, bool raw_output] )
7 * Description: Generate a keyed hash value using the HMAC method and the contents of a given file
8 * Source code: ext/hash/hash.c
9 * Alias to functions:
10*/
11
12echo "*** Testing hash() : error conditions ***\n";
13
14$file = __DIR__ . "hash_file.txt";
15$key = 'secret';
16
17echo "\n-- Testing hash_hmac_file() function with less than expected no. of arguments --\n";
18var_dump(hash_hmac_file());
19var_dump(hash_hmac_file('crc32'));
20var_dump(hash_hmac_file('crc32', $file));
21
22echo "\n-- Testing hash_hmac_file() function with more than expected no. of arguments --\n";
23$extra_arg = 10;
24hash_hmac_file('crc32', $file, $key, TRUE, $extra_arg);
25
26echo "\n-- Testing hash_hmac_file() function with invalid hash algorithm --\n";
27hash_hmac_file('foo', $file, $key, TRUE);
28
29echo "\n-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --\n";
30hash_hmac_file('crc32', $file, $key, TRUE);
31
32echo "\n-- Testing hash_hmac_file() function with bad path --\n";
33hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE);
34
35?>
36===Done===
37--EXPECTF--
38*** Testing hash() : error conditions ***
39
40-- Testing hash_hmac_file() function with less than expected no. of arguments --
41
42Warning: hash_hmac_file() expects at least 3 parameters, 0 given in %s on line %d
43NULL
44
45Warning: hash_hmac_file() expects at least 3 parameters, 1 given in %s on line %d
46NULL
47
48Warning: hash_hmac_file() expects at least 3 parameters, 2 given in %s on line %d
49NULL
50
51-- Testing hash_hmac_file() function with more than expected no. of arguments --
52
53Warning: hash_hmac_file() expects at most 4 parameters, 5 given in %s on line %d
54
55-- Testing hash_hmac_file() function with invalid hash algorithm --
56
57Warning: hash_hmac_file(): Unknown hashing algorithm: foo in %s on line %d
58
59-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --
60
61Warning: hash_hmac_file(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
62
63-- Testing hash_hmac_file() function with bad path --
64
65Warning: hash_hmac_file(): Invalid path in %s on line %d
66===Done===
67