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$data = b'string_val';
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 "Class A object";
43	}
44}
45
46class classWithoutToString
47{
48}
49
50// heredoc string
51$heredoc = <<<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      // float data
66      'float 10.5' => 10.5,
67      'float -10.5' => -10.5,
68      'float 12.3456789000e10' => 12.3456789000e10,
69      'float -12.3456789000e10' => -12.3456789000e10,
70      'float .5' => .5,
71
72      // array data
73      'empty array' => array(),
74      'int indexed array' => $index_array,
75      'associative array' => $assoc_array,
76      'nested arrays' => array('foo', $index_array, $assoc_array),
77
78      // null data
79      'uppercase NULL' => NULL,
80      'lowercase null' => null,
81
82      // boolean data
83      'lowercase true' => true,
84      'lowercase false' =>false,
85      'uppercase TRUE' =>TRUE,
86      'uppercase FALSE' =>FALSE,
87
88      // empty data
89      'empty string DQ' => "",
90      'empty string SQ' => '',
91
92      // string data
93      'string DQ' => "string",
94      'string SQ' => 'string',
95      'mixed case string' => "sTrInG",
96      'heredoc' => $heredoc,
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 mode
113
114foreach($inputs as $valueType =>$value) {
115      echo "\n--$valueType--\n";
116      var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $value, $iv)));
117};
118
119fclose($fp);
120
121?>
122===DONE===
123--EXPECTF--
124*** Testing mcrypt_cbc() : usage variation ***
125
126--float 10.5--
127Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
128string(32) "983d5edc5f77fe42e2372a0339dc22b0"
129
130--float -10.5--
131Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
132string(32) "983d5edc5f77fe42e2372a0339dc22b0"
133
134--float 12.3456789000e10--
135Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
136string(32) "983d5edc5f77fe42e2372a0339dc22b0"
137
138--float -12.3456789000e10--
139Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
140string(32) "983d5edc5f77fe42e2372a0339dc22b0"
141
142--float .5--
143Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
144string(32) "5f781523f696d596e4b809d72197a0cc"
145
146--empty array--
147Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
148string(32) "5f781523f696d596e4b809d72197a0cc"
149
150--int indexed array--
151Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
152string(32) "983d5edc5f77fe42e2372a0339dc22b0"
153
154--associative array--
155Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
156string(32) "983d5edc5f77fe42e2372a0339dc22b0"
157
158--nested arrays--
159Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
160string(32) "983d5edc5f77fe42e2372a0339dc22b0"
161
162--uppercase NULL--
163Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
164string(32) "5f781523f696d596e4b809d72197a0cc"
165
166--lowercase null--
167Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
168string(32) "5f781523f696d596e4b809d72197a0cc"
169
170--lowercase true--
171Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
172string(32) "983d5edc5f77fe42e2372a0339dc22b0"
173
174--lowercase false--
175Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
176string(32) "5f781523f696d596e4b809d72197a0cc"
177
178--uppercase TRUE--
179Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
180string(32) "983d5edc5f77fe42e2372a0339dc22b0"
181
182--uppercase FALSE--
183Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
184string(32) "5f781523f696d596e4b809d72197a0cc"
185
186--empty string DQ--
187Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
188string(32) "5f781523f696d596e4b809d72197a0cc"
189
190--empty string SQ--
191Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
192string(32) "5f781523f696d596e4b809d72197a0cc"
193
194--string DQ--
195Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
196string(32) "5f781523f696d596e4b809d72197a0cc"
197
198--string SQ--
199Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
200string(32) "5f781523f696d596e4b809d72197a0cc"
201
202--mixed case string--
203Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
204string(32) "5f781523f696d596e4b809d72197a0cc"
205
206--heredoc--
207Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
208string(32) "5f781523f696d596e4b809d72197a0cc"
209
210--instance of classWithToString--
211Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
212Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
213string(32) "983d5edc5f77fe42e2372a0339dc22b0"
214
215--instance of classWithoutToString--
216Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
217Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
218string(32) "983d5edc5f77fe42e2372a0339dc22b0"
219
220--undefined var--
221Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
222string(32) "5f781523f696d596e4b809d72197a0cc"
223
224--unset var--
225Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
226string(32) "5f781523f696d596e4b809d72197a0cc"
227
228--resource--
229Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
230string(32) "983d5edc5f77fe42e2372a0339dc22b0"
231===DONE===
232