PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mcrypt/tests/mcrypt_decrypt_variation5.php

http://github.com/facebook/hiphop-php
PHP | 113 lines | 64 code | 24 blank | 25 comment | 2 complexity | 805608105391fe90a447abc87e056173 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
  3. * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
  4. * Source code: ext/mcrypt/mcrypt.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
  8. // Define error handler
  9. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  10. if (error_reporting() != 0) {
  11. // report non-silenced errors
  12. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  13. }
  14. }
  15. set_error_handler('test_error_handler');
  16. // Initialise function arguments not being substituted (if any)
  17. $cipher = MCRYPT_TRIPLEDES;
  18. $key = b"string_val\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  19. $data = b'string_val';
  20. $mode = MCRYPT_MODE_CBC;
  21. //get an unset variable
  22. $unset_var = 10;
  23. unset ($unset_var);
  24. // define some classes
  25. class classWithToString
  26. {
  27. public function __toString() {
  28. return b"Class A object";
  29. }
  30. }
  31. class classWithoutToString
  32. {
  33. }
  34. // heredoc string
  35. $heredoc = b<<<EOT
  36. hello world
  37. EOT;
  38. // get a resource variable
  39. $fp = fopen(__FILE__, "r");
  40. // add arrays
  41. $index_array = array (1, 2, 3);
  42. $assoc_array = array ('one' => 1, 'two' => 2);
  43. //array of values to iterate over
  44. $inputs = array(
  45. // int data
  46. 'int 0' => 0,
  47. 'int 1' => 1,
  48. 'int 12345' => 12345,
  49. 'int -12345' => -2345,
  50. // float data
  51. 'float 10.5' => 10.5,
  52. 'float -10.5' => -10.5,
  53. 'float 12.3456789000e10' => 12.3456789000e10,
  54. 'float -12.3456789000e10' => -12.3456789000e10,
  55. 'float .5' => .5,
  56. // array data
  57. 'empty array' => array(),
  58. 'int indexed array' => $index_array,
  59. 'associative array' => $assoc_array,
  60. 'nested arrays' => array('foo', $index_array, $assoc_array),
  61. // null data
  62. 'uppercase NULL' => NULL,
  63. 'lowercase null' => null,
  64. // boolean data
  65. 'lowercase true' => true,
  66. 'lowercase false' =>false,
  67. 'uppercase TRUE' =>TRUE,
  68. 'uppercase FALSE' =>FALSE,
  69. // empty data
  70. 'empty string DQ' => "",
  71. 'empty string SQ' => '',
  72. // object data
  73. 'instance of classWithToString' => new classWithToString(),
  74. 'instance of classWithoutToString' => new classWithoutToString(),
  75. // undefined data
  76. 'undefined var' => @$undefined_var,
  77. // unset data
  78. 'unset var' => @$unset_var,
  79. // resource variable
  80. 'resource' => $fp
  81. );
  82. // loop through each element of the array for iv
  83. foreach($inputs as $valueType =>$value) {
  84. echo "\n--$valueType--\n";
  85. var_dump(bin2hex(mcrypt_decrypt($cipher, $key, $data, $mode, $value)));
  86. };
  87. fclose($fp);
  88. ?>
  89. ===DONE===