mcrypt_cbc_variation4.phpt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. $key = b"string_val\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  28. $data = b'string_val';
  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 "Class A object";
  38. }
  39. }
  40. class classWithoutToString
  41. {
  42. }
  43. // heredoc string
  44. $heredoc = <<<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. // float data
  55. 'float 10.5' => 10.5,
  56. 'float -10.5' => -10.5,
  57. 'float 12.3456789000e10' => 12.3456789000e10,
  58. 'float -12.3456789000e10' => -12.3456789000e10,
  59. 'float .5' => .5,
  60. // array data
  61. 'empty array' => array(),
  62. 'int indexed array' => $index_array,
  63. 'associative array' => $assoc_array,
  64. 'nested arrays' => array('foo', $index_array, $assoc_array),
  65. // null data
  66. 'uppercase NULL' => NULL,
  67. 'lowercase null' => null,
  68. // boolean data
  69. 'lowercase true' => true,
  70. 'lowercase false' =>false,
  71. 'uppercase TRUE' =>TRUE,
  72. 'uppercase FALSE' =>FALSE,
  73. // empty data
  74. 'empty string DQ' => "",
  75. 'empty string SQ' => '',
  76. // string data
  77. 'string DQ' => "string",
  78. 'string SQ' => 'string',
  79. 'mixed case string' => "sTrInG",
  80. 'heredoc' => $heredoc,
  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 mode
  92. foreach($inputs as $valueType =>$value) {
  93. echo "\n--$valueType--\n";
  94. var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $value, $iv)));
  95. };
  96. fclose($fp);
  97. ?>
  98. ===DONE===
  99. --EXPECTF--
  100. *** Testing mcrypt_cbc() : usage variation ***
  101. --float 10.5--
  102. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  103. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  104. --float -10.5--
  105. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  106. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  107. --float 12.3456789000e10--
  108. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  109. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  110. --float -12.3456789000e10--
  111. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  112. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  113. --float .5--
  114. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  115. string(32) "5f781523f696d596e4b809d72197a0cc"
  116. --empty array--
  117. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  118. string(32) "5f781523f696d596e4b809d72197a0cc"
  119. --int indexed array--
  120. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  121. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  122. --associative array--
  123. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  124. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  125. --nested arrays--
  126. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  127. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  128. --uppercase NULL--
  129. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  130. string(32) "5f781523f696d596e4b809d72197a0cc"
  131. --lowercase null--
  132. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  133. string(32) "5f781523f696d596e4b809d72197a0cc"
  134. --lowercase true--
  135. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  136. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  137. --lowercase false--
  138. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  139. string(32) "5f781523f696d596e4b809d72197a0cc"
  140. --uppercase TRUE--
  141. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  142. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  143. --uppercase FALSE--
  144. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  145. string(32) "5f781523f696d596e4b809d72197a0cc"
  146. --empty string DQ--
  147. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  148. string(32) "5f781523f696d596e4b809d72197a0cc"
  149. --empty string SQ--
  150. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  151. string(32) "5f781523f696d596e4b809d72197a0cc"
  152. --string DQ--
  153. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  154. string(32) "5f781523f696d596e4b809d72197a0cc"
  155. --string SQ--
  156. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  157. string(32) "5f781523f696d596e4b809d72197a0cc"
  158. --mixed case string--
  159. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  160. string(32) "5f781523f696d596e4b809d72197a0cc"
  161. --heredoc--
  162. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  163. string(32) "5f781523f696d596e4b809d72197a0cc"
  164. --instance of classWithToString--
  165. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  166. Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
  167. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  168. --instance of classWithoutToString--
  169. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  170. Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
  171. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  172. --undefined var--
  173. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  174. string(32) "5f781523f696d596e4b809d72197a0cc"
  175. --unset var--
  176. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  177. string(32) "5f781523f696d596e4b809d72197a0cc"
  178. --resource--
  179. Error: 8192 - Function mcrypt_cbc() is deprecated, %s(%d)
  180. string(32) "983d5edc5f77fe42e2372a0339dc22b0"
  181. ===DONE===