PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 114 lines | 64 code | 24 blank | 26 comment | 2 complexity | d3b02b632f92365919b76a8c43741ac9 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_encrypt(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_encrypt() : 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. //in php, it incorrectly reports problems with iv in ECB mode.
  21. $mode = MCRYPT_MODE_CBC;
  22. //get an unset variable
  23. $unset_var = 10;
  24. unset ($unset_var);
  25. // define some classes
  26. class classWithToString
  27. {
  28. public function __toString() {
  29. return b"Class A object";
  30. }
  31. }
  32. class classWithoutToString
  33. {
  34. }
  35. // heredoc string
  36. $heredoc = b<<<EOT
  37. hello world
  38. EOT;
  39. // get a resource variable
  40. $fp = fopen(__FILE__, "r");
  41. // add arrays
  42. $index_array = array (1, 2, 3);
  43. $assoc_array = array ('one' => 1, 'two' => 2);
  44. //array of values to iterate over
  45. $inputs = array(
  46. // int data
  47. 'int 0' => 0,
  48. 'int 1' => 1,
  49. 'int 12345' => 12345,
  50. 'int -12345' => -2345,
  51. // float data
  52. 'float 10.5' => 10.5,
  53. 'float -10.5' => -10.5,
  54. 'float 12.3456789000e10' => 12.3456789000e10,
  55. 'float -12.3456789000e10' => -12.3456789000e10,
  56. 'float .5' => .5,
  57. // array data
  58. 'empty array' => array(),
  59. 'int indexed array' => $index_array,
  60. 'associative array' => $assoc_array,
  61. 'nested arrays' => array('foo', $index_array, $assoc_array),
  62. // null data
  63. 'uppercase NULL' => NULL,
  64. 'lowercase null' => null,
  65. // boolean data
  66. 'lowercase true' => true,
  67. 'lowercase false' =>false,
  68. 'uppercase TRUE' =>TRUE,
  69. 'uppercase FALSE' =>FALSE,
  70. // empty data
  71. 'empty string DQ' => "",
  72. 'empty string SQ' => '',
  73. // object data
  74. 'instance of classWithToString' => new classWithToString(),
  75. 'instance of classWithoutToString' => new classWithoutToString(),
  76. // undefined data
  77. 'undefined var' => @$undefined_var,
  78. // unset data
  79. 'unset var' => @$unset_var,
  80. // resource variable
  81. 'resource' => $fp
  82. );
  83. // loop through each element of the array for iv
  84. foreach($inputs as $valueType =>$value) {
  85. echo "\n--$valueType--\n";
  86. var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $value)));
  87. };
  88. fclose($fp);
  89. ?>
  90. ===DONE===