Base64DotSlashOrderedTest.php 972 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. use \ParagonIE\ConstantTime\Base64DotSlashOrdered;
  3. class Base64DotSlashOrderedTest extends PHPUnit\Framework\TestCase
  4. {
  5. /**
  6. * @covers Base64DotSlashOrdered::encode()
  7. * @covers Base64DotSlashOrdered::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 = Base64DotSlashOrdered::encode($random);
  15. $this->assertSame(
  16. $random,
  17. Base64DotSlashOrdered::decode($enc)
  18. );
  19. $unpadded = \rtrim($enc, '=');
  20. $this->assertSame(
  21. $random,
  22. Base64DotSlashOrdered::decode($unpadded)
  23. );
  24. $this->assertSame(
  25. $random,
  26. Base64DotSlashOrdered::decode($unpadded)
  27. );
  28. }
  29. }
  30. }
  31. }