~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/mcrypt/tests/mcrypt_ecb_variation2.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
Test mcrypt_ecb() 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_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
 
 
17
echo "*** Testing mcrypt_ecb() : 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
$data = b'string_val';
 
31
$mode = MCRYPT_ENCRYPT;
 
32
$iv = b'01234567';
 
33
 
 
34
//get an unset variable
 
35
$unset_var = 10;
 
36
unset ($unset_var);
 
37
 
 
38
// define some classes
 
39
class classWithToString
 
40
{
 
41
        public function __toString() {
 
42
                return b"Class A object";
 
43
        }
 
44
}
 
45
 
 
46
class classWithoutToString
 
47
{
 
48
}
 
49
 
 
50
// heredoc string
 
51
$heredoc = b<<<EOT
 
52
hello world
 
53
EOT;
 
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 key
 
113
 
 
114
foreach($inputs as $valueType =>$value) {
 
115
      echo "\n--$valueType--\n";
 
116
      var_dump(bin2hex(mcrypt_ecb($cipher, $value, $data, $mode, $iv)));
 
117
};
 
118
 
 
119
fclose($fp);
 
120
 
 
121
?>
 
122
===DONE===
 
123
--EXPECTF--
 
124
*** Testing mcrypt_ecb() : usage variation ***
 
125
 
 
126
--int 0--
 
127
string(32) "e469e6b066f9600e1eefd8f53365f96c"
 
128
 
 
129
--int 1--
 
130
string(32) "e469e6b066f9600e1eefd8f53365f96c"
 
131
 
 
132
--int 12345--
 
133
string(32) "d74e5f51d1199bcfa61f80168e913007"
 
134
 
 
135
--int -12345--
 
136
string(32) "17fe485ed735abb34c1dd4455af7b79c"
 
137
 
 
138
--float 10.5--
 
139
string(32) "cd735509aa4013a130e011686d66ae01"
 
140
 
 
141
--float -10.5--
 
142
string(32) "a57d99d6d5813039abf50fc50d631e47"
 
143
 
 
144
--float 12.3456789000e10--
 
145
string(32) "f17ede0bfdaa4408f545f7f4c8b040d2"
 
146
 
 
147
--float -12.3456789000e10--
 
148
string(32) "326f64e3b9bd5a6beb0a9b52a09a5a48"
 
149
 
 
150
--float .5--
 
151
string(32) "2aedf7661cd4d8c7593f44c58718e2b8"
 
152
 
 
153
--empty array--
 
154
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
 
155
string(0) ""
 
156
 
 
157
--int indexed array--
 
158
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
 
159
string(0) ""
 
160
 
 
161
--associative array--
 
162
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
 
163
string(0) ""
 
164
 
 
165
--nested arrays--
 
166
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, array given, %s(%d)
 
167
string(0) ""
 
168
 
 
169
--uppercase NULL--
 
170
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
171
 
 
172
--lowercase null--
 
173
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
174
 
 
175
--lowercase true--
 
176
string(32) "e469e6b066f9600e1eefd8f53365f96c"
 
177
 
 
178
--lowercase false--
 
179
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
180
 
 
181
--uppercase TRUE--
 
182
string(32) "e469e6b066f9600e1eefd8f53365f96c"
 
183
 
 
184
--uppercase FALSE--
 
185
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
186
 
 
187
--empty string DQ--
 
188
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
189
 
 
190
--empty string SQ--
 
191
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
192
 
 
193
--instance of classWithToString--
 
194
string(32) "1fd3514d8ced44d04d9dc7511fce33ef"
 
195
 
 
196
--instance of classWithoutToString--
 
197
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, object given, %s(%d)
 
198
string(0) ""
 
199
 
 
200
--undefined var--
 
201
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
202
 
 
203
--unset var--
 
204
string(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
 
205
 
 
206
--resource--
 
207
Error: 2 - mcrypt_ecb() expects parameter 2 to be string, resource given, %s(%d)
 
208
string(0) ""
 
209
===DONE===
 
210