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$mode = MCRYPT_ENCRYPT; 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 b"Class A object"; 45 } 46} 47 48class classWithoutToString 49{ 50} 51 52// heredoc string 53$heredoc = b<<<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 // int data 68 'int 0' => 0, 69 'int 1' => 1, 70 'int 12345' => 12345, 71 'int -12345' => -2345, 72 73 // float data 74 'float 10.5' => 10.5, 75 'float -10.5' => -10.5, 76 'float 12.3456789000e10' => 12.3456789000e10, 77 'float -12.3456789000e10' => -12.3456789000e10, 78 'float .5' => .5, 79 80 // array data 81 'empty array' => array(), 82 'int indexed array' => $index_array, 83 'associative array' => $assoc_array, 84 'nested arrays' => array('foo', $index_array, $assoc_array), 85 86 // null data 87 'uppercase NULL' => NULL, 88 'lowercase null' => null, 89 90 // boolean data 91 'lowercase true' => true, 92 'lowercase false' =>false, 93 'uppercase TRUE' =>TRUE, 94 'uppercase FALSE' =>FALSE, 95 96 // empty data 97 'empty string DQ' => "", 98 'empty string SQ' => '', 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 data 115 116foreach($inputs as $valueType =>$value) { 117 echo "\n--$valueType--\n"; 118 var_dump(bin2hex(mcrypt_ecb($cipher, $key, $value, $mode, $iv))); 119}; 120 121fclose($fp); 122 123?> 124===DONE=== 125--EXPECTF-- 126*** Testing mcrypt_ecb() : usage variation *** 127 128--int 0-- 129string(16) "51dc9cd9179b718b" 130 131--int 1-- 132string(16) "619c335f8c4f9cbf" 133 134--int 12345-- 135string(16) "b1258d67ab73de00" 136 137--int -12345-- 138string(16) "8eecf134443bd6b9" 139 140--float 10.5-- 141string(16) "34b5750a793baff5" 142 143--float -10.5-- 144string(16) "7a605f2aacc8a11d" 145 146--float 12.3456789000e10-- 147string(32) "74a0d7026ae586f476d4b17808851e86" 148 149--float -12.3456789000e10-- 150string(32) "bfb155997017986c01090afebd62c7ca" 151 152--float .5-- 153string(16) "cc60ac201164b6c7" 154 155--empty array-- 156Error: 2 - mcrypt_ecb() expects parameter 3 to be string, array given, %s(%d) 157string(0) "" 158 159--int indexed array-- 160Error: 2 - mcrypt_ecb() expects parameter 3 to be string, array given, %s(%d) 161string(0) "" 162 163--associative array-- 164Error: 2 - mcrypt_ecb() expects parameter 3 to be string, array given, %s(%d) 165string(0) "" 166 167--nested arrays-- 168Error: 2 - mcrypt_ecb() expects parameter 3 to be string, array given, %s(%d) 169string(0) "" 170 171--uppercase NULL-- 172string(16) "6ece228c41457539" 173 174--lowercase null-- 175string(16) "6ece228c41457539" 176 177--lowercase true-- 178string(16) "619c335f8c4f9cbf" 179 180--lowercase false-- 181string(16) "6ece228c41457539" 182 183--uppercase TRUE-- 184string(16) "619c335f8c4f9cbf" 185 186--uppercase FALSE-- 187string(16) "6ece228c41457539" 188 189--empty string DQ-- 190string(16) "6ece228c41457539" 191 192--empty string SQ-- 193string(16) "6ece228c41457539" 194 195--instance of classWithToString-- 196string(32) "749c3b4d16731d98370128754b7c930f" 197 198--instance of classWithoutToString-- 199Error: 2 - mcrypt_ecb() expects parameter 3 to be string, object given, %s(%d) 200string(0) "" 201 202--undefined var-- 203string(16) "6ece228c41457539" 204 205--unset var-- 206string(16) "6ece228c41457539" 207 208--resource-- 209Error: 2 - mcrypt_ecb() expects parameter 3 to be string, resource given, %s(%d) 210string(0) "" 211===DONE=== 212 213