summaryrefslogtreecommitdiffstats
path: root/tests/EncodingTest.php
diff options
context:
space:
mode:
authorParagon Initiative Enterprises <security@paragonie.com>2016-03-12 16:36:00 -0500
committerScott <scott@paragonie.com>2016-03-12 16:36:00 -0500
commit226bfbfbcb7524a4e16b9fa58105a5932b22dc2a (patch)
tree56ac4099bab812af5a5e5462425b4e1950da116f /tests/EncodingTest.php
parent5cb35a7cc7451a0f77205e7fa7e6e00412afe7b5 (diff)
downloadconstant_time_encoding-226bfbfbcb7524a4e16b9fa58105a5932b22dc2a.zip
constant_time_encoding-226bfbfbcb7524a4e16b9fa58105a5932b22dc2a.tar.gz
constant_time_encoding-226bfbfbcb7524a4e16b9fa58105a5932b22dc2a.tar.bz2
Improve test coverage
Diffstat (limited to 'tests/EncodingTest.php')
-rw-r--r--tests/EncodingTest.php55
1 files changed, 42 insertions, 13 deletions
diff --git a/tests/EncodingTest.php b/tests/EncodingTest.php
index 17a7af2..41e2db1 100644
--- a/tests/EncodingTest.php
+++ b/tests/EncodingTest.php
@@ -149,22 +149,51 @@ class EncodingTest extends PHPUnit_Framework_TestCase
);
}
+ /**
+ * @covers Encoding::hexDecode()
+ * @covers Encoding::hexEncode()
+ * @covers Encoding::base64Decode()
+ * @covers Encoding::base64Encode()
+ * @covers Encoding::base32Decode()
+ * @covers Encoding::base32Encode()
+ */
public function testBasicEncoding()
{
- $str = random_bytes(33);
- $enc = base64_encode($str);
- $this->assertEquals(
- $str,
- Encoding::base64Decode($enc)
- );
+ // Re-run the test at least 3 times for each length
+ for ($j = 0; $j < 3; ++$j) {
+ for ($i = 1; $i < 84; ++$i) {
+ $rand = random_bytes($i);
+ $enc = Encoding::hexEncode($rand);
+ $this->assertEquals(
+ $rand,
+ Encoding::hexDecode($enc)
+ );
+
+ $enc = Encoding::base32Encode($rand);
+ $this->assertEquals(
+ $rand,
+ Encoding::base32Decode($enc)
+ );
+
+ $enc = Encoding::base64Encode($rand);
+
+ $this->assertEquals(
+ bin2hex($rand),
+ bin2hex(Encoding::base64Decode($enc)),
+ "Length: " . $i
+ );
- for ($i = 1; $i < 34; ++$i) {
- $rand = random_bytes($i);
- $enc = Encoding::base32Encode($rand);
- $this->assertEquals(
- bin2hex($rand),
- bin2hex(Encoding::base32Decode($enc))
- );
+ $enc = Encoding::base64EncodeDotSlash($rand);
+ $this->assertEquals(
+ bin2hex($rand),
+ bin2hex(Encoding::base64DecodeDotSlash($enc))
+ );
+ $enc = Encoding::base64EncodeDotSlashOrdered($rand);
+ $this->assertEquals(
+ bin2hex($rand),
+ bin2hex(Encoding::base64DecodeDotSlashOrdered($enc))
+ );
+ }
}
}
} \ No newline at end of file