PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/mcrypt/tests/mcrypt_ecb_variation4.php

http://github.com/facebook/hiphop-php
PHP | 114 lines | 64 code | 25 blank | 25 comment | 1 complexity | 6293ca17506fc25dff31027d356ceeb9 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. <?hh
  2. error_reporting(E_ALL & ~E_DEPRECATED);
  3. /* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
  4. * Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
  5. * Source code: ext/mcrypt/mcrypt.c
  6. * Alias to functions:
  7. */
  8. echo "*** Testing mcrypt_ecb() : usage variation ***\n";
  9. // Define error handler
  10. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  11. if ($err_no & error_reporting()) {
  12. // report non-silenced errors
  13. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  14. }
  15. }
  16. set_error_handler(fun('test_error_handler'));
  17. // Initialise function arguments not being substituted (if any)
  18. $cipher = MCRYPT_TRIPLEDES;
  19. $key = b"string_val\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  20. $data = b'string_val';
  21. $iv = b'01234567';
  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 "Class A object";
  30. }
  31. }
  32. class classWithoutToString
  33. {
  34. }
  35. // heredoc string
  36. $heredoc = <<<EOT
  37. hello world
  38. EOT;
  39. // get a resource variable
  40. $fp = fopen(__FILE__, "r");
  41. // add arrays
  42. $index_array = varray [1, 2, 3];
  43. $assoc_array = darray ['one' => 1, 'two' => 2];
  44. //array of values to iterate over
  45. $inputs = darray[
  46. // float data
  47. 'float 10.5' => 10.5,
  48. 'float -10.5' => -10.5,
  49. 'float 12.3456789000e10' => 12.3456789000e10,
  50. 'float -12.3456789000e10' => -12.3456789000e10,
  51. 'float .5' => .5,
  52. // array data
  53. 'empty array' => varray[],
  54. 'int indexed array' => $index_array,
  55. 'associative array' => $assoc_array,
  56. 'nested arrays' => varray['foo', $index_array, $assoc_array],
  57. // null data
  58. 'uppercase NULL' => NULL,
  59. 'lowercase null' => null,
  60. // boolean data
  61. 'lowercase true' => true,
  62. 'lowercase false' =>false,
  63. 'uppercase TRUE' =>TRUE,
  64. 'uppercase FALSE' =>FALSE,
  65. // empty data
  66. 'empty string DQ' => "",
  67. 'empty string SQ' => '',
  68. // string data
  69. 'string DQ' => "string",
  70. 'string SQ' => 'string',
  71. 'mixed case string' => "sTrInG",
  72. 'heredoc' => $heredoc,
  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 mode
  84. foreach($inputs as $valueType =>$value) {
  85. echo "\n--$valueType--\n";
  86. var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $value, $iv)));
  87. };
  88. fclose($fp);
  89. echo "===DONE===\n";