Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_encrypt_variation5.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mcrypt_encrypt() function : usage variation
! 3: --SKIPIF--
! 4: <?php
! 5: if (!extension_loaded("mcrypt")) {
! 6: print "skip - mcrypt extension not loaded";
! 7: }
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11: /* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
! 12: * Description: OFB 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:
! 17: echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
! 18:
! 19: // Define error handler
! 20: function 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: }
! 26: set_error_handler('test_error_handler');
! 27:
! 28: // Initialise function arguments not being substituted (if any)
! 29: $cipher = MCRYPT_TRIPLEDES;
! 30: $key = b'string_val';
! 31: $data = b'string_val';
! 32: //in php, it incorrectly reports problems with iv in ECB mode.
! 33: $mode = MCRYPT_MODE_CBC;
! 34:
! 35: //get an unset variable
! 36: $unset_var = 10;
! 37: unset ($unset_var);
! 38:
! 39: // define some classes
! 40: class classWithToString
! 41: {
! 42: public function __toString() {
! 43: return b"Class A object";
! 44: }
! 45: }
! 46:
! 47: class classWithoutToString
! 48: {
! 49: }
! 50:
! 51: // heredoc string
! 52: $heredoc = b<<<EOT
! 53: hello world
! 54: EOT;
! 55:
! 56: // get a resource variable
! 57: $fp = fopen(__FILE__, "r");
! 58:
! 59: // add arrays
! 60: $index_array = array (1, 2, 3);
! 61: $assoc_array = array ('one' => 1, 'two' => 2);
! 62:
! 63: //array of values to iterate over
! 64: $inputs = array(
! 65:
! 66: // int data
! 67: 'int 0' => 0,
! 68: 'int 1' => 1,
! 69: 'int 12345' => 12345,
! 70: 'int -12345' => -2345,
! 71:
! 72: // float data
! 73: 'float 10.5' => 10.5,
! 74: 'float -10.5' => -10.5,
! 75: 'float 12.3456789000e10' => 12.3456789000e10,
! 76: 'float -12.3456789000e10' => -12.3456789000e10,
! 77: 'float .5' => .5,
! 78:
! 79: // array data
! 80: 'empty array' => array(),
! 81: 'int indexed array' => $index_array,
! 82: 'associative array' => $assoc_array,
! 83: 'nested arrays' => array('foo', $index_array, $assoc_array),
! 84:
! 85: // null data
! 86: 'uppercase NULL' => NULL,
! 87: 'lowercase null' => null,
! 88:
! 89: // boolean data
! 90: 'lowercase true' => true,
! 91: 'lowercase false' =>false,
! 92: 'uppercase TRUE' =>TRUE,
! 93: 'uppercase FALSE' =>FALSE,
! 94:
! 95: // empty data
! 96: 'empty string DQ' => "",
! 97: 'empty string SQ' => '',
! 98:
! 99: // object data
! 100: 'instance of classWithToString' => new classWithToString(),
! 101: 'instance of classWithoutToString' => new classWithoutToString(),
! 102:
! 103: // undefined data
! 104: 'undefined var' => @$undefined_var,
! 105:
! 106: // unset data
! 107: 'unset var' => @$unset_var,
! 108:
! 109: // resource variable
! 110: 'resource' => $fp
! 111: );
! 112:
! 113: // loop through each element of the array for iv
! 114:
! 115: foreach($inputs as $valueType =>$value) {
! 116: echo "\n--$valueType--\n";
! 117: var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $value)));
! 118: };
! 119:
! 120: fclose($fp);
! 121:
! 122: ?>
! 123: ===DONE===
! 124: --EXPECTF--
! 125: *** Testing mcrypt_encrypt() : usage variation ***
! 126:
! 127: --int 0--
! 128: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 129: string(32) "6438db90653c4d3080c3ceab43618c05"
! 130:
! 131: --int 1--
! 132: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 133: string(32) "6438db90653c4d3080c3ceab43618c05"
! 134:
! 135: --int 12345--
! 136: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 137: string(32) "6438db90653c4d3080c3ceab43618c05"
! 138:
! 139: --int -12345--
! 140: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 141: string(32) "6438db90653c4d3080c3ceab43618c05"
! 142:
! 143: --float 10.5--
! 144: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 145: string(32) "6438db90653c4d3080c3ceab43618c05"
! 146:
! 147: --float -10.5--
! 148: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 149: string(32) "6438db90653c4d3080c3ceab43618c05"
! 150:
! 151: --float 12.3456789000e10--
! 152: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 153: string(32) "6438db90653c4d3080c3ceab43618c05"
! 154:
! 155: --float -12.3456789000e10--
! 156: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 157: string(32) "6438db90653c4d3080c3ceab43618c05"
! 158:
! 159: --float .5--
! 160: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 161: string(32) "6438db90653c4d3080c3ceab43618c05"
! 162:
! 163: --empty array--
! 164: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, array given, %s(%d)
! 165: string(0) ""
! 166:
! 167: --int indexed array--
! 168: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, array given, %s(%d)
! 169: string(0) ""
! 170:
! 171: --associative array--
! 172: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, array given, %s(%d)
! 173: string(0) ""
! 174:
! 175: --nested arrays--
! 176: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, array given, %s(%d)
! 177: string(0) ""
! 178:
! 179: --uppercase NULL--
! 180: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 181: string(32) "6438db90653c4d3080c3ceab43618c05"
! 182:
! 183: --lowercase null--
! 184: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 185: string(32) "6438db90653c4d3080c3ceab43618c05"
! 186:
! 187: --lowercase true--
! 188: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 189: string(32) "6438db90653c4d3080c3ceab43618c05"
! 190:
! 191: --lowercase false--
! 192: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 193: string(32) "6438db90653c4d3080c3ceab43618c05"
! 194:
! 195: --uppercase TRUE--
! 196: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 197: string(32) "6438db90653c4d3080c3ceab43618c05"
! 198:
! 199: --uppercase FALSE--
! 200: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 201: string(32) "6438db90653c4d3080c3ceab43618c05"
! 202:
! 203: --empty string DQ--
! 204: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 205: string(32) "6438db90653c4d3080c3ceab43618c05"
! 206:
! 207: --empty string SQ--
! 208: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 209: string(32) "6438db90653c4d3080c3ceab43618c05"
! 210:
! 211: --instance of classWithToString--
! 212: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 213: string(32) "6438db90653c4d3080c3ceab43618c05"
! 214:
! 215: --instance of classWithoutToString--
! 216: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, object given, %s(%d)
! 217: string(0) ""
! 218:
! 219: --undefined var--
! 220: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 221: string(32) "6438db90653c4d3080c3ceab43618c05"
! 222:
! 223: --unset var--
! 224: Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
! 225: string(32) "6438db90653c4d3080c3ceab43618c05"
! 226:
! 227: --resource--
! 228: Error: 2 - mcrypt_encrypt() expects parameter 5 to be string, resource given, %s(%d)
! 229: string(0) ""
! 230: ===DONE===
! 231:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>