1--TEST--
2Test mcrypt_ecb() 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_ecb(string cipher, string key, string data, int mode, string iv)
12 * Description: ECB 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_ecb() : 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_ecb($cipher, $key, $data, $value, $iv)));
117};
118
119fclose($fp);
120
121?>
122===DONE===
123--EXPECTF--
124*** Testing mcrypt_ecb() : usage variation ***
125
126--float 10.5--
127string(32) "a80c6cef6b42c8759143586a57bb7dc6"
128
129--float -10.5--
130string(32) "a80c6cef6b42c8759143586a57bb7dc6"
131
132--float 12.3456789000e10--
133string(32) "a80c6cef6b42c8759143586a57bb7dc6"
134
135--float -12.3456789000e10--
136string(32) "a80c6cef6b42c8759143586a57bb7dc6"
137
138--float .5--
139string(32) "6438db90653c4d300909aa02fd6163c2"
140
141--empty array--
142string(32) "6438db90653c4d300909aa02fd6163c2"
143
144--int indexed array--
145string(32) "a80c6cef6b42c8759143586a57bb7dc6"
146
147--associative array--
148string(32) "a80c6cef6b42c8759143586a57bb7dc6"
149
150--nested arrays--
151string(32) "a80c6cef6b42c8759143586a57bb7dc6"
152
153--uppercase NULL--
154string(32) "6438db90653c4d300909aa02fd6163c2"
155
156--lowercase null--
157string(32) "6438db90653c4d300909aa02fd6163c2"
158
159--lowercase true--
160string(32) "a80c6cef6b42c8759143586a57bb7dc6"
161
162--lowercase false--
163string(32) "6438db90653c4d300909aa02fd6163c2"
164
165--uppercase TRUE--
166string(32) "a80c6cef6b42c8759143586a57bb7dc6"
167
168--uppercase FALSE--
169string(32) "6438db90653c4d300909aa02fd6163c2"
170
171--empty string DQ--
172string(32) "6438db90653c4d300909aa02fd6163c2"
173
174--empty string SQ--
175string(32) "6438db90653c4d300909aa02fd6163c2"
176
177--string DQ--
178string(32) "6438db90653c4d300909aa02fd6163c2"
179
180--string SQ--
181string(32) "6438db90653c4d300909aa02fd6163c2"
182
183--mixed case string--
184string(32) "6438db90653c4d300909aa02fd6163c2"
185
186--heredoc--
187string(32) "6438db90653c4d300909aa02fd6163c2"
188
189--instance of classWithToString--
190Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
191string(32) "a80c6cef6b42c8759143586a57bb7dc6"
192
193--instance of classWithoutToString--
194Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
195string(32) "a80c6cef6b42c8759143586a57bb7dc6"
196
197--undefined var--
198string(32) "6438db90653c4d300909aa02fd6163c2"
199
200--unset var--
201string(32) "6438db90653c4d300909aa02fd6163c2"
202
203--resource--
204string(%d) %s
205===DONE===
206