mcrypt_cbc_variation2.phpt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. --TEST--
  2. Test mcrypt_cbc() 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_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. echo "*** Testing mcrypt_cbc() : usage variation ***\n";
  17. // Define error handler
  18. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  19. if (error_reporting() != 0) {
  20. // report non-silenced errors
  21. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  22. }
  23. }
  24. set_error_handler('test_error_handler');
  25. // Initialise function arguments not being substituted (if any)
  26. $cipher = MCRYPT_TRIPLEDES;
  27. $data = b'string_val';
  28. $mode = MCRYPT_ENCRYPT;
  29. $iv = b'01234567';
  30. //get an unset variable
  31. $unset_var = 10;
  32. unset ($unset_var);
  33. // define some classes
  34. class classWithToString
  35. {
  36. public function __toString() {
  37. return b"Class A object";
  38. }
  39. }
  40. class classWithoutToString
  41. {
  42. }
  43. // heredoc string
  44. $heredoc = b<<<EOT
  45. hello world
  46. EOT;
  47. // get a resource variable
  48. $fp = fopen(__FILE__, "r");
  49. // add arrays
  50. $index_array = array (1, 2, 3);
  51. $assoc_array = array ('one' => 1, 'two' => 2);
  52. //array of values to iterate over
  53. $inputs = array(
  54. // int data
  55. 'int 0' => 0,
  56. 'int 1' => 1,
  57. 'int 12345' => 12345,
  58. 'int -12345' => -2345,
  59. // float data
  60. 'float 10.5' => 10.5,
  61. 'float -10.5' => -10.5,
  62. 'float 12.3456789000e10' => 12.3456789000e10,
  63. 'float -12.3456789000e10' => -12.3456789000e10,
  64. 'float .5' => .5,
  65. // array data
  66. 'empty array' => array(),
  67. 'int indexed array' => $index_array,
  68. 'associative array' => $assoc_array,
  69. 'nested arrays' => array('foo', $index_array, $assoc_array),
  70. // null data
  71. 'uppercase NULL' => NULL,
  72. 'lowercase null' => null,
  73. // boolean data
  74. 'lowercase true' => true,
  75. 'lowercase false' =>false,
  76. 'uppercase TRUE' =>TRUE,
  77. 'uppercase FALSE' =>FALSE,
  78. // empty data
  79. 'empty string DQ' => "",
  80. 'empty string SQ' => '',
  81. // object data
  82. 'instance of classWithToString' => new classWithToString(),
  83. 'instance of classWithoutToString' => new classWithoutToString(),
  84. // undefined data
  85. 'undefined var' => @$undefined_var,
  86. // unset data
  87. 'unset var' => @$unset_var,
  88. // resource variable
  89. 'resource' => $fp
  90. );
  91. // loop through each element of the array for key
  92. foreach($inputs as $valueType =>$value) {
  93. echo "\n--$valueType--\n";
  94. var_dump(bin2hex(mcrypt_cbc($cipher, $value, $data, $mode, $iv)));
  95. };
  96. fclose($fp);
  97. ?>
  98. ===DONE===
  99. --EXPECTF--
  100. *** Testing mcrypt_cbc() : usage variation ***
  101. --int 0--
  102. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  103. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  104. string(0) ""
  105. --int 1--
  106. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  107. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  108. string(0) ""
  109. --int 12345--
  110. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  111. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  112. string(0) ""
  113. --int -12345--
  114. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  115. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  116. string(0) ""
  117. --float 10.5--
  118. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  119. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  120. string(0) ""
  121. --float -10.5--
  122. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  123. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  124. string(0) ""
  125. --float 12.3456789000e10--
  126. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  127. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  128. string(0) ""
  129. --float -12.3456789000e10--
  130. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  131. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  132. string(0) ""
  133. --float .5--
  134. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  135. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  136. string(0) ""
  137. --empty array--
  138. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  139. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
  140. string(0) ""
  141. --int indexed array--
  142. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  143. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
  144. string(0) ""
  145. --associative array--
  146. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  147. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
  148. string(0) ""
  149. --nested arrays--
  150. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  151. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, array given, %s(%d)
  152. string(0) ""
  153. --uppercase NULL--
  154. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  155. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  156. string(0) ""
  157. --lowercase null--
  158. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  159. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  160. string(0) ""
  161. --lowercase true--
  162. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  163. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  164. string(0) ""
  165. --lowercase false--
  166. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  167. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  168. string(0) ""
  169. --uppercase TRUE--
  170. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  171. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  172. string(0) ""
  173. --uppercase FALSE--
  174. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  175. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  176. string(0) ""
  177. --empty string DQ--
  178. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  179. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  180. string(0) ""
  181. --empty string SQ--
  182. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  183. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  184. string(0) ""
  185. --instance of classWithToString--
  186. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  187. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  188. string(0) ""
  189. --instance of classWithoutToString--
  190. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  191. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, object given, %s(%d)
  192. string(0) ""
  193. --undefined var--
  194. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  195. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  196. string(0) ""
  197. --unset var--
  198. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  199. Error: 2 - mcrypt_cbc(): Key of size %d not supported by this algorithm. Only keys of size 24 supported, %s(%d)
  200. string(0) ""
  201. --resource--
  202. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  203. Error: 2 - mcrypt_cbc() expects parameter 2 to be string, resource given, %s(%d)
  204. string(0) ""
  205. ===DONE===