Base32Test.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use \ParagonIE\ConstantTime\Base32;
  3. class Base32Test extends PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * @covers Base32::encode()
  7. * @covers Base32::decode()
  8. * @covers Base32::encodeUpper()
  9. * @covers Base32::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 = Base32::encode($random);
  17. $this->assertSame(
  18. $random,
  19. Base32::decode($enc)
  20. );
  21. $this->assertSame(
  22. Base32::encodeUnpadded($random),
  23. \rtrim(Base32::encode($random), '=')
  24. );
  25. $enc = Base32::encodeUpper($random);
  26. $this->assertSame(
  27. $random,
  28. Base32::decodeUpper($enc)
  29. );
  30. $this->assertSame(
  31. Base32::encodeUpperUnpadded($random),
  32. \rtrim(Base32::encodeUpper($random), '=')
  33. );
  34. }
  35. }
  36. }
  37. }