Base32HexTest.php 833 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. use \ParagonIE\ConstantTime\Base32Hex;
  3. class Base32HexTest extends PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * @covers Base32Hex::encode()
  7. * @covers Base32Hex::decode()
  8. * @covers Base32Hex::encodeUpper()
  9. * @covers Base32Hex::decodeUpper()
  10. */
  11. public function testRandom()
  12. {
  13. for ($i = 1; $i < 32; ++$i) {
  14. for ($j = 0; $j < 50; ++$j) {
  15. $random = \random_bytes($i);
  16. $enc = Base32Hex::encode($random);
  17. $this->assertSame(
  18. $random,
  19. Base32Hex::decode($enc)
  20. );
  21. $enc = Base32Hex::encodeUpper($random);
  22. $this->assertSame(
  23. $random,
  24. Base32Hex::decodeUpper($enc)
  25. );
  26. }
  27. }
  28. }
  29. }