import zend mcrypt tests
[hiphop-php.git] / hphp / test / zend / bad / ext-mcrypt / mcrypt_encrypt_variation5.php
blob311f78aa1544f69107cf6559a4c66e9abb35e643
1 <?php
2 /* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
3 * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
4 * Source code: ext/mcrypt/mcrypt.c
5 * Alias to functions:
6 */
8 echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
10 // Define error handler
11 function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
12 if (error_reporting() != 0) {
13 // report non-silenced errors
14 echo "Error: $err_no - $err_msg, $filename($linenum)\n";
17 set_error_handler('test_error_handler');
19 // Initialise function arguments not being substituted (if any)
20 $cipher = MCRYPT_TRIPLEDES;
21 $key = b'string_val';
22 $data = b'string_val';
23 //in php, it incorrectly reports problems with iv in ECB mode.
24 $mode = MCRYPT_MODE_CBC;
26 //get an unset variable
27 $unset_var = 10;
28 unset ($unset_var);
30 // define some classes
31 class classWithToString
33 public function __toString() {
34 return b"Class A object";
38 class classWithoutToString
42 // heredoc string
43 $heredoc = b<<<EOT
44 hello world
45 EOT;
47 // get a resource variable
48 $fp = fopen(__FILE__, "r");
50 // add arrays
51 $index_array = array (1, 2, 3);
52 $assoc_array = array ('one' => 1, 'two' => 2);
54 //array of values to iterate over
55 $inputs = array(
57 // int data
58 'int 0' => 0,
59 'int 1' => 1,
60 'int 12345' => 12345,
61 'int -12345' => -2345,
63 // float data
64 'float 10.5' => 10.5,
65 'float -10.5' => -10.5,
66 'float 12.3456789000e10' => 12.3456789000e10,
67 'float -12.3456789000e10' => -12.3456789000e10,
68 'float .5' => .5,
70 // array data
71 'empty array' => array(),
72 'int indexed array' => $index_array,
73 'associative array' => $assoc_array,
74 'nested arrays' => array('foo', $index_array, $assoc_array),
76 // null data
77 'uppercase NULL' => NULL,
78 'lowercase null' => null,
80 // boolean data
81 'lowercase true' => true,
82 'lowercase false' =>false,
83 'uppercase TRUE' =>TRUE,
84 'uppercase FALSE' =>FALSE,
86 // empty data
87 'empty string DQ' => "",
88 'empty string SQ' => '',
90 // object data
91 'instance of classWithToString' => new classWithToString(),
92 'instance of classWithoutToString' => new classWithoutToString(),
94 // undefined data
95 'undefined var' => @$undefined_var,
97 // unset data
98 'unset var' => @$unset_var,
100 // resource variable
101 'resource' => $fp
104 // loop through each element of the array for iv
106 foreach($inputs as $valueType =>$value) {
107 echo "\n--$valueType--\n";
108 var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $value)));
111 fclose($fp);
114 ===DONE===