]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - extlib/ParagonIE/ConstantTime/Base64.php
Merge branch 'nightly' into 'master'
[quix0rs-gnu-social.git] / extlib / ParagonIE / ConstantTime / Base64.php
index df801cc8ec203cf65432d8b1ada194ace312a1b4..7e6e24b937b1e0ed350a86afc9a2a62b02b344c1 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-declare(strict_types=1);
 namespace ParagonIE\ConstantTime;
 
 /**
@@ -41,7 +40,7 @@ abstract class Base64 implements EncoderInterface
      * @param string $src
      * @return string
      */
-    public static function encode(string $src): string
+    public static function encode($src)
     {
         $dest = '';
         $srcLen = Binary::safeStrlen($src);
@@ -83,18 +82,16 @@ abstract class Base64 implements EncoderInterface
      * 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] === '=') {
@@ -109,11 +106,6 @@ abstract class Base64 implements EncoderInterface
                     'Incorrect padding'
                 );
             }
-            if ($src[$srcLen - 1] === '=') {
-                throw new \RangeException(
-                    'Incorrect padding'
-                );
-            }
         } else {
             $src = \rtrim($src, '=');
             $srcLen = Binary::safeStrlen($src);
@@ -141,7 +133,6 @@ abstract class Base64 implements EncoderInterface
         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]);
@@ -151,7 +142,7 @@ abstract class Base64 implements EncoderInterface
                     ((($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',
@@ -179,7 +170,7 @@ abstract class Base64 implements EncoderInterface
      * @param int $src
      * @return int
      */
-    protected static function decode6Bits(int $src): int
+    protected static function decode6Bits($src)
     {
         $ret = -1;
 
@@ -208,7 +199,7 @@ abstract class Base64 implements EncoderInterface
      * @param int $src
      * @return string
      */
-    protected static function encode6Bits(int $src): string
+    protected static function encode6Bits($src)
     {
         $diff = 0x41;