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