diff options
author | Scott <scott@paragonie.com> | 2016-04-08 13:13:36 -0400 |
---|---|---|
committer | Scott <scott@paragonie.com> | 2016-04-08 13:13:36 -0400 |
commit | 94029642b52eddbe12d36161c3b6ceb8866d99d3 (patch) | |
tree | 61cecde8b1b1ad687c41f301cfddf186dea130f8 | |
parent | fdb1e311153233315e0f7699711e3845d81ed00f (diff) | |
download | constant_time_encoding-94029642b52eddbe12d36161c3b6ceb8866d99d3.zip constant_time_encoding-94029642b52eddbe12d36161c3b6ceb8866d99d3.tar.gz constant_time_encoding-94029642b52eddbe12d36161c3b6ceb8866d99d3.tar.bz2 |
Version 2.x requires PHP 7 and uses scalar type declarations
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | composer.json | 5 | ||||
-rw-r--r-- | src/Base32.php | 25 | ||||
-rw-r--r-- | src/Base32Hex.php | 9 | ||||
-rw-r--r-- | src/Base64.php | 9 | ||||
-rw-r--r-- | src/Base64DotSlash.php | 5 | ||||
-rw-r--r-- | src/Base64DotSlashOrdered.php | 5 | ||||
-rw-r--r-- | src/Base64UrlSafe.php | 5 | ||||
-rw-r--r-- | src/Binary.php | 1 | ||||
-rw-r--r-- | src/EncoderInterface.php | 5 | ||||
-rw-r--r-- | src/Encoding.php | 45 | ||||
-rw-r--r-- | src/Hex.php | 7 | ||||
-rw-r--r-- | src/RFC4648.php | 21 |
14 files changed, 78 insertions, 71 deletions
diff --git a/.travis.yml b/.travis.yml index 3a5adbd..b11cc55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,6 @@ sudo: false php: - "7.0" - - "5.6" - - "5.5" - "hhvm" matrix: @@ -18,9 +18,8 @@ Our fork offers the following enchancements: ## PHP Version Requirements -This library should work on any [supported version of PHP](https://secure.php.net/supported-versions.php). -It *may* work on earlier versions, but we **do not** guarantee it. If it -doesn't, we **will not** fix it to work on earlier versions of PHP. +Version 2 of this library should work on **PHP 7** or newer. For PHP 5 +support, see [the v1.x branch](https://github.com/paragonie/constant_time_encoding/tree/v1.x). ## How to Install diff --git a/composer.json b/composer.json index 3e90d7c..46c354e 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,10 @@ "source": "https://github.com/paragonie/constant_time_encoding" }, "require": { - "php": "^5.3|^7" + "php": "^7" }, "require-dev": { - "phpunit/phpunit": "4.*|5.*", - "paragonie/random_compat": "^1.4|^2.0" + "phpunit/phpunit": "4.*|5.*" }, "autoload": { "psr-4": { diff --git a/src/Base32.php b/src/Base32.php index 28b8ca2..6231cc5 100644 --- a/src/Base32.php +++ b/src/Base32.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -38,7 +39,7 @@ abstract class Base32 implements EncoderInterface * @param string $src * @return string */ - public static function decode($src) + public static function decode(string $src): string { return static::doDecode($src, false); } @@ -49,7 +50,7 @@ abstract class Base32 implements EncoderInterface * @param string $src * @return string */ - public static function decodeUpper($src) + public static function decodeUpper(string $src): string { return static::doDecode($src, true); } @@ -60,7 +61,7 @@ abstract class Base32 implements EncoderInterface * @param string $src * @return string */ - public static function encode($src) + public static function encode(string $src): string { return static::doEncode($src, false); } @@ -71,7 +72,7 @@ abstract class Base32 implements EncoderInterface * @param string $src * @return string */ - public static function encodeUpper($src) + public static function encodeUpper(string $src): string { return static::doEncode($src, true); } @@ -83,7 +84,7 @@ abstract class Base32 implements EncoderInterface * @param int $src * @return int */ - protected static function decode5Bits($src) + protected static function decode5Bits(int $src): int { $ret = -1; @@ -105,7 +106,7 @@ abstract class Base32 implements EncoderInterface * @param int $src * @return int */ - protected static function decode5BitsUpper($src) + protected static function decode5BitsUpper(int $src): int { $ret = -1; @@ -125,7 +126,7 @@ abstract class Base32 implements EncoderInterface * @param $src * @return string */ - protected static function encode5Bits($src) + protected static function encode5Bits(int $src): string { $diff = 0x61; @@ -144,7 +145,7 @@ abstract class Base32 implements EncoderInterface * @param $src * @return string */ - protected static function encode5BitsUpper($src) + protected static function encode5BitsUpper(int $src): string { $diff = 0x41; @@ -158,11 +159,11 @@ abstract class Base32 implements EncoderInterface /** * Base32 decoding * - * @param $src + * @param string $src * @param bool $upper * @return string */ - protected static function doDecode($src, $upper = false) + protected static function doDecode(string $src, bool $upper = false): string { // We do this to reduce code duplication: $method = $upper @@ -314,7 +315,7 @@ abstract class Base32 implements EncoderInterface * @param bool $upper * @return string */ - protected static function doEncode($src, $upper = false) + protected static function doEncode(string $src, bool $upper = false): string { // We do this to reduce code duplication: $method = $upper @@ -386,4 +387,4 @@ abstract class Base32 implements EncoderInterface } return $dest; } -}
\ No newline at end of file +} diff --git a/src/Base32Hex.php b/src/Base32Hex.php index f37cf1d..5aff0a6 100644 --- a/src/Base32Hex.php +++ b/src/Base32Hex.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -39,7 +40,7 @@ abstract class Base32Hex extends Base32 * @param int $src * @return int */ - protected static function decode5Bits($src) + protected static function decode5Bits(int $src): int { $ret = -1; @@ -59,7 +60,7 @@ abstract class Base32Hex extends Base32 * @param int $src * @return int */ - protected static function decode5BitsUpper($src) + protected static function decode5BitsUpper(int $src): int { $ret = -1; @@ -79,7 +80,7 @@ abstract class Base32Hex extends Base32 * @param int $src * @return string */ - protected static function encode5Bits($src) + protected static function encode5Bits(int $src): string { $src += 0x30; @@ -98,7 +99,7 @@ abstract class Base32Hex extends Base32 * @param int $src * @return string */ - protected static function encode5BitsUpper($src) + protected static function encode5BitsUpper(int $src): string { $src += 0x30; diff --git a/src/Base64.php b/src/Base64.php index 46fc78d..480c851 100644 --- a/src/Base64.php +++ b/src/Base64.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -40,7 +41,7 @@ abstract class Base64 implements EncoderInterface * @param string $src * @return string */ - public static function encode($src) + public static function encode(string $src): string { $dest = ''; $srcLen = Binary::safeStrlen($src); @@ -85,7 +86,7 @@ abstract class Base64 implements EncoderInterface * @return string|bool * @throws \RangeException */ - public static function decode($src) + public static function decode(string $src): string { // Remove padding $srcLen = Binary::safeStrlen($src); @@ -163,7 +164,7 @@ abstract class Base64 implements EncoderInterface * @param int $src * @return int */ - protected static function decode6Bits($src) + protected static function decode6Bits(int $src): int { $ret = -1; @@ -192,7 +193,7 @@ abstract class Base64 implements EncoderInterface * @param int $src * @return string */ - protected static function encode6Bits($src) + protected static function encode6Bits(int $src): string { $diff = 0x41; diff --git a/src/Base64DotSlash.php b/src/Base64DotSlash.php index 1604597..7f97513 100644 --- a/src/Base64DotSlash.php +++ b/src/Base64DotSlash.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -43,7 +44,7 @@ abstract class Base64DotSlash extends Base64 * @param int $src * @return int */ - protected static function decode6Bits($src) + protected static function decode6Bits(int $src): int { $ret = -1; @@ -69,7 +70,7 @@ abstract class Base64DotSlash extends Base64 * @param int $src * @return string */ - protected static function encode6Bits($src) + protected static function encode6Bits(int $src): string { $src += 0x2e; diff --git a/src/Base64DotSlashOrdered.php b/src/Base64DotSlashOrdered.php index 3f5e6b4..3fb4209 100644 --- a/src/Base64DotSlashOrdered.php +++ b/src/Base64DotSlashOrdered.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -43,7 +44,7 @@ abstract class Base64DotSlashOrdered extends Base64 * @param int $src * @return int */ - protected static function decode6Bits($src) + protected static function decode6Bits(int $src): int { $ret = -1; @@ -66,7 +67,7 @@ abstract class Base64DotSlashOrdered extends Base64 * @param int $src * @return string */ - protected static function encode6Bits($src) + protected static function encode6Bits(int $src): string { $src += 0x2e; diff --git a/src/Base64UrlSafe.php b/src/Base64UrlSafe.php index 3e4edf8..f250095 100644 --- a/src/Base64UrlSafe.php +++ b/src/Base64UrlSafe.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -44,7 +45,7 @@ abstract class Base64UrlSafe extends Base64 * @param int $src * @return int */ - protected static function decode6Bits($src) + protected static function decode6Bits(int $src): int { $ret = -1; @@ -73,7 +74,7 @@ abstract class Base64UrlSafe extends Base64 * @param int $src * @return string */ - protected static function encode6Bits($src) + protected static function encode6Bits(int $src): string { $diff = 0x41; diff --git a/src/Binary.php b/src/Binary.php index 4447b19..dd32349 100644 --- a/src/Binary.php +++ b/src/Binary.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** diff --git a/src/EncoderInterface.php b/src/EncoderInterface.php index 8ecb45e..79744ce 100644 --- a/src/EncoderInterface.php +++ b/src/EncoderInterface.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -37,7 +38,7 @@ interface EncoderInterface * @param string $bin_string (raw binary) * @return string */ - public static function encode($bin_string); + public static function encode(string $bin_string): string; /** * Convert a binary string into a hexadecimal string without cache-timing @@ -46,5 +47,5 @@ interface EncoderInterface * @param string $encoded_string * @return string (raw binary) */ - public static function decode($encoded_string); + public static function decode(string $encoded_string): string; } diff --git a/src/Encoding.php b/src/Encoding.php index 55a3c78..8ea8aec 100644 --- a/src/Encoding.php +++ b/src/Encoding.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -36,7 +37,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32Encode($str) + public static function base32Encode(string $str): string { return Base32::encode($str); } @@ -47,7 +48,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32EncodeUpper($str) + public static function base32EncodeUpper(string $str): string { return Base32::encodeUpper($str); } @@ -58,7 +59,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32Decode($str) + public static function base32Decode(string $str): string { return Base32::decode($str); } @@ -69,7 +70,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32DecodeUpper($str) + public static function base32DecodeUpper(string $str): string { return Base32::decodeUpper($str); } @@ -80,7 +81,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32HexEncode($str) + public static function base32HexEncode(string $str): string { return Base32Hex::encode($str); } @@ -92,7 +93,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32HexEncodeUpper($str) + public static function base32HexEncodeUpper(string $str): string { return Base32Hex::encodeUpper($str); } @@ -103,7 +104,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32HexDecode($str) + public static function base32HexDecode(string $str): string { return Base32Hex::decode($str); } @@ -114,7 +115,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base32HexDecodeUpper($str) + public static function base32HexDecodeUpper(string $str): string { return Base32Hex::decodeUpper($str); } @@ -125,7 +126,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base64Encode($str) + public static function base64Encode(string $str): string { return Base64::encode($str); } @@ -136,7 +137,7 @@ abstract class Encoding * @param $str * @return string */ - public static function base64Decode($str) + public static function base64Decode(string $str): string { return Base64::decode($str); } @@ -148,9 +149,9 @@ abstract class Encoding * @param $src * @return string */ - public static function base64EncodeDotSlash($src) + public static function base64EncodeDotSlash(string $str): string { - return Base64DotSlash::encode($src); + return Base64DotSlash::encode($str); } /** @@ -162,9 +163,9 @@ abstract class Encoding * @return bool|string * @throws \RangeException */ - public static function base64DecodeDotSlash($src) + public static function base64DecodeDotSlash(string $str): string { - return Base64DotSlash::decode($src); + return Base64DotSlash::decode($str); } /** @@ -174,9 +175,9 @@ abstract class Encoding * @param $src * @return string */ - public static function base64EncodeDotSlashOrdered($src) + public static function base64EncodeDotSlashOrdered(string $str): string { - return Base64DotSlashOrdered::encode($src); + return Base64DotSlashOrdered::encode($str); } /** @@ -188,9 +189,9 @@ abstract class Encoding * @return bool|string * @throws \RangeException */ - public static function base64DecodeDotSlashOrdered($src) + public static function base64DecodeDotSlashOrdered(string $str): string { - return Base64DotSlashOrdered::decode($src); + return Base64DotSlashOrdered::decode($str); } /** @@ -200,7 +201,7 @@ abstract class Encoding * @param string $bin_string (raw binary) * @return string */ - public static function hexEncode($bin_string) + public static function hexEncode(string $bin_string): string { return Hex::encode($bin_string); } @@ -213,7 +214,7 @@ abstract class Encoding * @return string (raw binary) * @throws \RangeException */ - public static function hexDecode($hex_string) + public static function hexDecode(string $hex_string): string { return Hex::decode($hex_string); } @@ -225,7 +226,7 @@ abstract class Encoding * @param string $bin_string (raw binary) * @return string */ - public static function hexEncodeUpper($bin_string) + public static function hexEncodeUpper(string $bin_string): string { return Hex::encodeUpper($bin_string); } @@ -237,7 +238,7 @@ abstract class Encoding * @param string $bin_string (raw binary) * @return string */ - public static function hexDecodeUpper($bin_string) + public static function hexDecodeUpper(string $bin_string): string { return Hex::decode($bin_string); } diff --git a/src/Hex.php b/src/Hex.php index 32962c0..fac29d8 100644 --- a/src/Hex.php +++ b/src/Hex.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -37,7 +38,7 @@ abstract class Hex implements EncoderInterface * @param string $bin_string (raw binary) * @return string */ - public static function encode($bin_string) + public static function encode(string $bin_string): string { $hex = ''; $len = Binary::safeStrlen($bin_string); @@ -61,7 +62,7 @@ abstract class Hex implements EncoderInterface * @param string $bin_string (raw binary) * @return string */ - public static function encodeUpper($bin_string) + public static function encodeUpper(string $bin_string): string { $hex = ''; $len = Binary::safeStrlen($bin_string); @@ -86,7 +87,7 @@ abstract class Hex implements EncoderInterface * @return string (raw binary) * @throws \RangeException */ - public static function decode($hex_string) + public static function decode(string $hex_string): string { $hex_pos = 0; $bin = ''; diff --git a/src/RFC4648.php b/src/RFC4648.php index 58efdcc..04af38b 100644 --- a/src/RFC4648.php +++ b/src/RFC4648.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace ParagonIE\ConstantTime; /** @@ -41,7 +42,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base64Encode($str) + public function base64Encode(string $str): string { return Base64::encode($str); } @@ -54,7 +55,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base64Decode($str) + public function base64Decode(string $str): string { return Base64::decode($str); } @@ -67,7 +68,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base64UrlSafeEncode($str) + public function base64UrlSafeEncode(string $str): string { return Base64UrlSafe::encode($str); } @@ -80,7 +81,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base64UrlSafeDecode($str) + public function base64UrlSafeDecode(string $str): string { return Base64UrlSafe::decode($str); } @@ -93,7 +94,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base32Encode($str) + public function base32Encode(string $str): string { return Base32::encodeUpper($str); } @@ -106,7 +107,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base32Decode($str) + public function base32Decode(string $str): string { return Base32::decodeUpper($str); } @@ -119,7 +120,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base32HexEncode($str) + public function base32HexEncode(string $str): string { return Base32::encodeUpper($str); } @@ -132,7 +133,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base32HexDecode($str) + public function base32HexDecode(string $str): string { return Base32::decodeUpper($str); } @@ -145,7 +146,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base16Encode($str) + public function base16Encode(string $str): string { return Hex::encodeUpper($str); } @@ -158,7 +159,7 @@ abstract class RFC4648 * @param string $str * @return string */ - public function base16Decode($str) + public function base16Decode(string $str): string { return Hex::decode($str); } |