Base64DotSlashTest.php 916 B

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