McryptRijndael128Test.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * The RandomLib library for securely generating random numbers and strings in PHP
  4. *
  5. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  6. * @copyright 2011 The Authors
  7. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  8. * @version Build @@version@@
  9. */
  10. namespace RandomLib\Mixer;
  11. use SecurityLib\Strength;
  12. class McryptRijndael128Test extends \PHPUnit_Framework_TestCase
  13. {
  14. public static function provideMix()
  15. {
  16. $data = array(
  17. array(array(), ''),
  18. array(array('', ''), ''),
  19. array(array('a'), '61'),
  20. array(array('a', 'b'), '6a'),
  21. array(array('aa', 'ba'), '688d'),
  22. array(array('ab', 'bb'), 'f8bc'),
  23. array(array('aa', 'bb'), 'a0f3'),
  24. array(array('aa', 'bb', 'cc'), '87c3'),
  25. array(array('aabbcc', 'bbccdd', 'ccddee'), '7cf2273e46c7'),
  26. );
  27. return $data;
  28. }
  29. protected function setUp()
  30. {
  31. if (!\extension_loaded('mcrypt') || PHP_VERSION_ID >= 70100) {
  32. $this->markTestSkipped('mcrypt extension is not available');
  33. }
  34. }
  35. public function testConstructWithoutArgument()
  36. {
  37. $hash = new McryptRijndael128();
  38. $this->assertTrue($hash instanceof \RandomLib\Mixer);
  39. }
  40. public function testGetStrength()
  41. {
  42. $strength = new Strength(Strength::HIGH);
  43. $actual = McryptRijndael128::getStrength();
  44. $this->assertEquals($actual, $strength);
  45. }
  46. public function testTest()
  47. {
  48. $actual = McryptRijndael128::test();
  49. $this->assertTrue($actual);
  50. }
  51. /**
  52. * @dataProvider provideMix
  53. */
  54. public function testMix($parts, $result)
  55. {
  56. $mixer = new McryptRijndael128();
  57. $actual = $mixer->mix($parts);
  58. $this->assertEquals($result, bin2hex($actual));
  59. }
  60. }