Annotation of embedaddon/php/ext/hash/tests/hash_hmac_file_basic.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test hash_hmac_file() function : basic functionality 
                      3: --SKIPIF--
                      4: <?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
                      5: --FILE--
                      6: <?php
                      7: 
                      8: 
                      9: /* Prototype  : string hash_hmac_file ( string algo, string filename, string key [, bool raw_output] )
                     10:  * Description: Generate a keyed hash value using the HMAC method and the contents of a given file
                     11:  * Source code: ext/hash/hash.c
                     12:  * Alias to functions: 
                     13: */
                     14: 
                     15: echo "*** Testing hash_hmac_file() : basic functionality ***\n";
                     16: 
                     17: $file = dirname(__FILE__) . "hash_hmac_file.txt";
                     18: /* Creating a temporary file file */
                     19: if (($fp = fopen( $file, "w+")) == FALSE) {
                     20:        echo "Cannot create file ($file)";
                     21:     exit;
                     22: }      
                     23: 
                     24: /* Writing into file */ 
                     25: $content = "This is a sample string used to test the hash_hmac_file function with various hashing algorithms";
                     26: if (is_writable($file)) {
                     27:   if (fwrite($fp, $content) === FALSE) {
                     28:     echo "Cannot write to file ($file)";
                     29:     exit;
                     30:   }
                     31: }
                     32: 
                     33: // close the files 
                     34: fclose($fp);
                     35: 
                     36: $key = 'secret';
                     37: 
                     38: 
                     39: echo "adler32: " . hash_hmac_file('adler32', $file, $key) . "\n";
                     40: echo "crc32: " . hash_hmac_file('crc32', $file, $key) . "\n";
                     41: echo "gost: " . hash_hmac_file('gost', $file, $key) . "\n";
                     42: echo "haval128,3: " . hash_hmac_file('haval128,3', $file, $key) . "\n";
                     43: echo "md2: " . hash_hmac_file('md2', $file, $key) . "\n";
                     44: echo "md4: " . hash_hmac_file('md4', $file, $key) . "\n";
                     45: echo "md5: " . hash_hmac_file('md5', $file, $key) . "\n";
                     46: echo "ripemd128: " . hash_hmac_file('ripemd128', $file, $key) . "\n";
                     47: echo "ripemd160: " . hash_hmac_file('ripemd160', $file, $key) . "\n";
                     48: echo "ripemd256: " . hash_hmac_file('ripemd256', $file, $key) . "\n";
                     49: echo "ripemd320: " . hash_hmac_file('ripemd320', $file, $key) . "\n";
                     50: echo "sha1: " . hash_hmac_file('sha1', $file, $key) . "\n";
                     51: echo "sha256: " . hash_hmac_file('sha256', $file, $key) . "\n";
                     52: echo "sha384: " . hash_hmac_file('sha384', $file, $key) . "\n";
                     53: echo "sha512: " . hash_hmac_file('sha512', $file, $key) . "\n";
                     54: echo "snefru: " . hash_hmac_file('snefru', $file, $key) . "\n";
                     55: echo "tiger192,3: " . hash_hmac_file('tiger192,3', $file, $key) . "\n";
                     56: echo "whirlpool: " . hash_hmac_file('whirlpool', $file, $key) . "\n";
                     57: 
                     58: echo "adler32(raw): " . bin2hex(hash_hmac_file('adler32', $file, $key, TRUE)) . "\n";
                     59: echo "md5(raw): " . bin2hex(hash_hmac_file('md5', $file, $key, TRUE)). "\n";
                     60: echo "sha256(raw): " . bin2hex(hash_hmac_file('sha256', $file, $key, TRUE)). "\n";
                     61: 
                     62: echo "Error cases:\n";
                     63: hash_hmac_file();
                     64: hash_hmac_file('foo', $file);
                     65: hash_hmac_file('foo', $file, $key, TRUE, 10);
                     66: 
                     67: unlink($file);
                     68: 
                     69: ?>
                     70: ===Done===
                     71: --EXPECTF--
                     72: *** Testing hash_hmac_file() : basic functionality ***
                     73: adler32: 0f8c02f9
                     74: crc32: f2a60b9c
                     75: gost: 94c39a40d5db852a8dc3d24e37eebf2d53e3d711457c59cd02b614f792a9d918
                     76: haval128,3: e8fcff647f1a675acb429130fb94a17e
                     77: md2: a685475e600314bb549ab4f33c3b27cb
                     78: md4: cbc6bff781f48f57378d3effa27553e4
                     79: md5: 8bddf39dd1c566c27acc7fa85ec36acf
                     80: ripemd128: 03269b76bf61d508c50f038cbe9ba691
                     81: ripemd160: 94652211292268d97eb63344a3a05d3009f9d2d3
                     82: ripemd256: b6ab414cc1630e1e474fefa41976d252f38ca7cf401552774e71736165e512e7
                     83: ripemd320: 71271a649265740eed4b9931417f979fd81eba6288f4e08ff2997bc3dd6858da054d53a9f1fffe8c
                     84: sha1: 7f338d17b72371091abd28f451bc8d1f3a9eb3b6
                     85: sha256: 9135286ca4c84dec711e4b831f6cd39e672e5ff93d011321274eb76733cc1e40
                     86: sha384: 364fdc45a4c742763366ab5d3d1c17c24057e6c3b641607a36d969f00c88da25b19c8b88c8632411e3a0a02397f88aca
                     87: sha512: d460aabdf0353655059ed0d408efa91f19c4cda46acc2a4e0adf4764b06951c899fbb2ed41519db78b58ff7be17b1b2910aebe674a56861b232143571b35c83f
                     88: snefru: 7b79787e1c1d926b6cc98327f05c5d04ba6227ab51c1398661861196016ef34c
1.1.1.2 ! misho      89: tiger192,3: ca89badf843ba68e3fae5832635aa848a72a4bc11676edd4
1.1       misho      90: whirlpool: 37a0fbb90547690d5e5e11c046f6654ffdb7bab15e16d9d79c7d85765cc4bdcbfd9df8db7a3ce9558f3f244fead00ca29cf05297f75596555195a0683f15d69f
                     91: adler32(raw): 0f8c02f9
                     92: md5(raw): 8bddf39dd1c566c27acc7fa85ec36acf
                     93: sha256(raw): 9135286ca4c84dec711e4b831f6cd39e672e5ff93d011321274eb76733cc1e40
                     94: Error cases:
                     95: 
                     96: Warning: hash_hmac_file() expects at least 3 parameters, 0 given in %s on line %d
                     97: 
                     98: Warning: hash_hmac_file() expects at least 3 parameters, 2 given in %s on line %d
                     99: 
                    100: Warning: hash_hmac_file() expects at most 4 parameters, 5 given in %s on line %d
                    101: ===Done===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>