mcrypt_ecb_variation4.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. --TEST--
  2. Test mcrypt_ecb() 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. error_reporting(E_ALL & ~E_DEPRECATED);
  12. /* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
  13. * Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
  14. * Source code: ext/mcrypt/mcrypt.c
  15. * Alias to functions:
  16. */
  17. echo "*** Testing mcrypt_ecb() : usage variation ***\n";
  18. // Define error handler
  19. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  20. if ($err_no & error_reporting()) {
  21. // report non-silenced errors
  22. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  23. }
  24. }
  25. set_error_handler('test_error_handler');
  26. // Initialise function arguments not being substituted (if any)
  27. $cipher = MCRYPT_TRIPLEDES;
  28. $key = b"string_val\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  29. $data = b'string_val';
  30. $iv = b'01234567';
  31. //get an unset variable
  32. $unset_var = 10;
  33. unset ($unset_var);
  34. // define some classes
  35. class classWithToString
  36. {
  37. public function __toString() {
  38. return "Class A object";
  39. }
  40. }
  41. class classWithoutToString
  42. {
  43. }
  44. // heredoc string
  45. $heredoc = <<<EOT
  46. hello world
  47. EOT;
  48. // get a resource variable
  49. $fp = fopen(__FILE__, "r");
  50. // add arrays
  51. $index_array = array (1, 2, 3);
  52. $assoc_array = array ('one' => 1, 'two' => 2);
  53. //array of values to iterate over
  54. $inputs = array(
  55. // float data
  56. 'float 10.5' => 10.5,
  57. 'float -10.5' => -10.5,
  58. 'float 12.3456789000e10' => 12.3456789000e10,
  59. 'float -12.3456789000e10' => -12.3456789000e10,
  60. 'float .5' => .5,
  61. // array data
  62. 'empty array' => array(),
  63. 'int indexed array' => $index_array,
  64. 'associative array' => $assoc_array,
  65. 'nested arrays' => array('foo', $index_array, $assoc_array),
  66. // null data
  67. 'uppercase NULL' => NULL,
  68. 'lowercase null' => null,
  69. // boolean data
  70. 'lowercase true' => true,
  71. 'lowercase false' =>false,
  72. 'uppercase TRUE' =>TRUE,
  73. 'uppercase FALSE' =>FALSE,
  74. // empty data
  75. 'empty string DQ' => "",
  76. 'empty string SQ' => '',
  77. // string data
  78. 'string DQ' => "string",
  79. 'string SQ' => 'string',
  80. 'mixed case string' => "sTrInG",
  81. 'heredoc' => $heredoc,
  82. // object data
  83. 'instance of classWithToString' => new classWithToString(),
  84. 'instance of classWithoutToString' => new classWithoutToString(),
  85. // undefined data
  86. 'undefined var' => @$undefined_var,
  87. // unset data
  88. 'unset var' => @$unset_var,
  89. // resource variable
  90. 'resource' => $fp
  91. );
  92. // loop through each element of the array for mode
  93. foreach($inputs as $valueType =>$value) {
  94. echo "\n--$valueType--\n";
  95. var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $value, $iv)));
  96. };
  97. fclose($fp);
  98. ?>
  99. ===DONE===
  100. --EXPECTF--
  101. *** Testing mcrypt_ecb() : usage variation ***
  102. --float 10.5--
  103. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  104. --float -10.5--
  105. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  106. --float 12.3456789000e10--
  107. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  108. --float -12.3456789000e10--
  109. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  110. --float .5--
  111. string(32) "6438db90653c4d300909aa02fd6163c2"
  112. --empty array--
  113. string(32) "6438db90653c4d300909aa02fd6163c2"
  114. --int indexed array--
  115. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  116. --associative array--
  117. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  118. --nested arrays--
  119. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  120. --uppercase NULL--
  121. string(32) "6438db90653c4d300909aa02fd6163c2"
  122. --lowercase null--
  123. string(32) "6438db90653c4d300909aa02fd6163c2"
  124. --lowercase true--
  125. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  126. --lowercase false--
  127. string(32) "6438db90653c4d300909aa02fd6163c2"
  128. --uppercase TRUE--
  129. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  130. --uppercase FALSE--
  131. string(32) "6438db90653c4d300909aa02fd6163c2"
  132. --empty string DQ--
  133. string(32) "6438db90653c4d300909aa02fd6163c2"
  134. --empty string SQ--
  135. string(32) "6438db90653c4d300909aa02fd6163c2"
  136. --string DQ--
  137. string(32) "6438db90653c4d300909aa02fd6163c2"
  138. --string SQ--
  139. string(32) "6438db90653c4d300909aa02fd6163c2"
  140. --mixed case string--
  141. string(32) "6438db90653c4d300909aa02fd6163c2"
  142. --heredoc--
  143. string(32) "6438db90653c4d300909aa02fd6163c2"
  144. --instance of classWithToString--
  145. Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
  146. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  147. --instance of classWithoutToString--
  148. Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
  149. string(32) "a80c6cef6b42c8759143586a57bb7dc6"
  150. --undefined var--
  151. string(32) "6438db90653c4d300909aa02fd6163c2"
  152. --unset var--
  153. string(32) "6438db90653c4d300909aa02fd6163c2"
  154. --resource--
  155. string(%d) %s
  156. ===DONE===