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