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$data = b'string_val'; 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 key 115 116foreach($inputs as $valueType =>$value) { 117 echo "\n--$valueType--\n"; 118 var_dump(bin2hex(mcrypt_ecb($cipher, $value, $data, $mode, $iv))); 119}; 120 121fclose($fp); 122 123?> 124===DONE=== 125--EXPECTF-- 126*** Testing mcrypt_ecb() : usage variation *** 127 128--int 0-- 129Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 130string(0) "" 131 132--int 1-- 133Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 134string(0) "" 135 136--int 12345-- 137Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 138string(0) "" 139 140--int -12345-- 141Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 142string(0) "" 143 144--float 10.5-- 145Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 146string(0) "" 147 148--float -10.5-- 149Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 150string(0) "" 151 152--float 12.3456789000e10-- 153Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 154string(0) "" 155 156--float -12.3456789000e10-- 157Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 158string(0) "" 159 160--float .5-- 161Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 162string(0) "" 163 164--empty array-- 165Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d) 166string(0) "" 167 168--int indexed array-- 169Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d) 170string(0) "" 171 172--associative array-- 173Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d) 174string(0) "" 175 176--nested arrays-- 177Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d) 178string(0) "" 179 180--uppercase NULL-- 181Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 182string(0) "" 183 184--lowercase null-- 185Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 186string(0) "" 187 188--lowercase true-- 189Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 190string(0) "" 191 192--lowercase false-- 193Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 194string(0) "" 195 196--uppercase TRUE-- 197Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 198string(0) "" 199 200--uppercase FALSE-- 201Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 202string(0) "" 203 204--empty string DQ-- 205Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 206string(0) "" 207 208--empty string SQ-- 209Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 210string(0) "" 211 212--instance of classWithToString-- 213Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 214string(0) "" 215 216--instance of classWithoutToString-- 217Error: 2 - mcrypt_ecb() expects parameter 2 to be string, object given, %s(%d) 218string(0) "" 219 220--undefined var-- 221Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 222string(0) "" 223 224--unset var-- 225Error: 2 - mcrypt_ecb(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d) 226string(0) "" 227 228--resource-- 229Error: 2 - mcrypt_ecb() expects parameter 2 to be string, resource given, %s(%d) 230string(0) "" 231===DONE=== 232 233