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