<?php
-declare(strict_types=1);
namespace ParagonIE\ConstantTime;
/**
* @param string $src
* @return string
*/
- public static function encode(string $src): string
+ public static function encode($src)
{
$dest = '';
$srcLen = Binary::safeStrlen($src);
* Base64 character set "./[A-Z][a-z][0-9]"
*
* @param string $src
- * @param bool $strictPadding
* @return string|bool
* @throws \RangeException
*/
- public static function decode(string $src, bool $strictPadding = false): string
+ public static function decode($src, $strictPadding = false)
{
// Remove padding
$srcLen = Binary::safeStrlen($src);
if ($srcLen === 0) {
return '';
}
-
if ($strictPadding) {
if (($srcLen & 3) === 0) {
if ($src[$srcLen - 1] === '=') {
'Incorrect padding'
);
}
- if ($src[$srcLen - 1] === '=') {
- throw new \RangeException(
- 'Incorrect padding'
- );
- }
} else {
$src = \rtrim($src, '=');
$srcLen = Binary::safeStrlen($src);
if ($i < $srcLen) {
$chunk = \unpack('C*', Binary::safeSubstr($src, $i, $srcLen - $i));
$c0 = static::decode6Bits($chunk[1]);
-
if ($i + 2 < $srcLen) {
$c1 = static::decode6Bits($chunk[2]);
$c2 = static::decode6Bits($chunk[3]);
((($c1 << 4) | ($c2 >> 2)) & 0xff)
);
$err |= ($c0 | $c1 | $c2) >> 8;
- } elseif ($i + 1 < $srcLen) {
+ } elseif($i + 1 < $srcLen) {
$c1 = static::decode6Bits($chunk[2]);
$dest .= \pack(
'C',
* @param int $src
* @return int
*/
- protected static function decode6Bits(int $src): int
+ protected static function decode6Bits($src)
{
$ret = -1;
* @param int $src
* @return string
*/
- protected static function encode6Bits(int $src): string
+ protected static function encode6Bits($src)
{
$diff = 0x41;