1--TEST-- 2Test mcrypt_ecb() function : usage variation 3--SKIPIF-- 4<?php 5if (!extension_loaded("mcrypt")) { 6 print "skip - mcrypt extension not loaded"; 7} 8?> 9--FILE-- 10<?php 11error_reporting(E_ALL & ~E_DEPRECATED); 12 13/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv) 14 * Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv 15 * Source code: ext/mcrypt/mcrypt.c 16 * Alias to functions: 17 */ 18 19echo "*** Testing mcrypt_ecb() : usage variation ***\n"; 20 21// Define error handler 22function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 23 if ($err_no & error_reporting()) { 24 // report non-silenced errors 25 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 26 } 27} 28set_error_handler('test_error_handler'); 29 30// Initialise function arguments not being substituted (if any) 31$cipher = MCRYPT_TRIPLEDES; 32$key = b"string_val\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; 33$data = b'string_val'; 34$iv = b'01234567'; 35 36//get an unset variable 37$unset_var = 10; 38unset ($unset_var); 39 40// define some classes 41class classWithToString 42{ 43 public function __toString() { 44 return "Class A object"; 45 } 46} 47 48class classWithoutToString 49{ 50} 51 52// heredoc string 53$heredoc = <<<EOT 54hello world 55EOT; 56 57// get a resource variable 58$fp = fopen(__FILE__, "r"); 59 60// add arrays 61$index_array = array (1, 2, 3); 62$assoc_array = array ('one' => 1, 'two' => 2); 63 64//array of values to iterate over 65$inputs = array( 66 67 // float data 68 'float 10.5' => 10.5, 69 'float -10.5' => -10.5, 70 'float 12.3456789000e10' => 12.3456789000e10, 71 'float -12.3456789000e10' => -12.3456789000e10, 72 'float .5' => .5, 73 74 // array data 75 'empty array' => array(), 76 'int indexed array' => $index_array, 77 'associative array' => $assoc_array, 78 'nested arrays' => array('foo', $index_array, $assoc_array), 79 80 // null data 81 'uppercase NULL' => NULL, 82 'lowercase null' => null, 83 84 // boolean data 85 'lowercase true' => true, 86 'lowercase false' =>false, 87 'uppercase TRUE' =>TRUE, 88 'uppercase FALSE' =>FALSE, 89 90 // empty data 91 'empty string DQ' => "", 92 'empty string SQ' => '', 93 94 // string data 95 'string DQ' => "string", 96 'string SQ' => 'string', 97 'mixed case string' => "sTrInG", 98 'heredoc' => $heredoc, 99 100 // object data 101 'instance of classWithToString' => new classWithToString(), 102 'instance of classWithoutToString' => new classWithoutToString(), 103 104 // undefined data 105 'undefined var' => @$undefined_var, 106 107 // unset data 108 'unset var' => @$unset_var, 109 110 // resource variable 111 'resource' => $fp 112); 113 114// loop through each element of the array for mode 115 116foreach($inputs as $valueType =>$value) { 117 echo "\n--$valueType--\n"; 118 var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $value, $iv))); 119}; 120 121fclose($fp); 122 123?> 124===DONE=== 125--EXPECTF-- 126*** Testing mcrypt_ecb() : usage variation *** 127 128--float 10.5-- 129string(32) "a80c6cef6b42c8759143586a57bb7dc6" 130 131--float -10.5-- 132string(32) "a80c6cef6b42c8759143586a57bb7dc6" 133 134--float 12.3456789000e10-- 135string(32) "a80c6cef6b42c8759143586a57bb7dc6" 136 137--float -12.3456789000e10-- 138string(32) "a80c6cef6b42c8759143586a57bb7dc6" 139 140--float .5-- 141string(32) "6438db90653c4d300909aa02fd6163c2" 142 143--empty array-- 144string(32) "6438db90653c4d300909aa02fd6163c2" 145 146--int indexed array-- 147string(32) "a80c6cef6b42c8759143586a57bb7dc6" 148 149--associative array-- 150string(32) "a80c6cef6b42c8759143586a57bb7dc6" 151 152--nested arrays-- 153string(32) "a80c6cef6b42c8759143586a57bb7dc6" 154 155--uppercase NULL-- 156string(32) "6438db90653c4d300909aa02fd6163c2" 157 158--lowercase null-- 159string(32) "6438db90653c4d300909aa02fd6163c2" 160 161--lowercase true-- 162string(32) "a80c6cef6b42c8759143586a57bb7dc6" 163 164--lowercase false-- 165string(32) "6438db90653c4d300909aa02fd6163c2" 166 167--uppercase TRUE-- 168string(32) "a80c6cef6b42c8759143586a57bb7dc6" 169 170--uppercase FALSE-- 171string(32) "6438db90653c4d300909aa02fd6163c2" 172 173--empty string DQ-- 174string(32) "6438db90653c4d300909aa02fd6163c2" 175 176--empty string SQ-- 177string(32) "6438db90653c4d300909aa02fd6163c2" 178 179--string DQ-- 180string(32) "6438db90653c4d300909aa02fd6163c2" 181 182--string SQ-- 183string(32) "6438db90653c4d300909aa02fd6163c2" 184 185--mixed case string-- 186string(32) "6438db90653c4d300909aa02fd6163c2" 187 188--heredoc-- 189string(32) "6438db90653c4d300909aa02fd6163c2" 190 191--instance of classWithToString-- 192Error: 8 - Object of class classWithToString could not be converted to int, %s(%d) 193string(32) "a80c6cef6b42c8759143586a57bb7dc6" 194 195--instance of classWithoutToString-- 196Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d) 197string(32) "a80c6cef6b42c8759143586a57bb7dc6" 198 199--undefined var-- 200string(32) "6438db90653c4d300909aa02fd6163c2" 201 202--unset var-- 203string(32) "6438db90653c4d300909aa02fd6163c2" 204 205--resource-- 206string(%d) %s 207===DONE=== 208