Skip to content

Commit

Permalink
Fix build failures.
Browse files Browse the repository at this point in the history
We have to remove 7.0 since Travis uses Composer 2 and our dependencies will not install on PHP 7.0
  • Loading branch information
paragonie-security committed Dec 6, 2020
1 parent f045e67 commit 5e64617
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sudo: false
matrix:
fast_finish: true
include:
- php: "7.0"
- php: "7.1"
- php: "7.2"
- php: "7.3"
Expand Down
10 changes: 5 additions & 5 deletions src/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ abstract class Base32 implements EncoderInterface
/**
* Decode a Base32-encoded string into raw binary
*
* @param string $src
* @param string $encodedString
* @param bool $strictPadding
* @return string
* @throws \TypeError
*/
public static function decode(string $src, bool $strictPadding = false): string
public static function decode(string $encodedString, bool $strictPadding = false): string
{
return static::doDecode($src, false, $strictPadding);
return static::doDecode($encodedString, false, $strictPadding);
}

/**
* Decode an uppercase Base32-encoded string into raw binary
*
* @param string $src
* @param bool $strictPadding
* @return string
* @throws \TypeError
*/
public static function decodeUpper(string $src, bool $strictPadding = false): string
{
Expand Down
20 changes: 10 additions & 10 deletions src/Base64.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ protected static function doEncode(string $src, bool $pad = true): string
*
* Base64 character set "./[A-Z][a-z][0-9]"
*
* @param string $src
* @param string $encodedString
* @param bool $strictPadding
* @return string
* @throws \RangeException
* @throws \TypeError
* @psalm-suppress RedundantCondition
*/
public static function decode(string $src, bool $strictPadding = false): string
public static function decode(string $encodedString, bool $strictPadding = false): string
{
// Remove padding
$srcLen = Binary::safeStrlen($src);
$srcLen = Binary::safeStrlen($encodedString);
if ($srcLen === 0) {
return '';
}

if ($strictPadding) {
if (($srcLen & 3) === 0) {
if ($src[$srcLen - 1] === '=') {
if ($encodedString[$srcLen - 1] === '=') {
$srcLen--;
if ($src[$srcLen - 1] === '=') {
if ($encodedString[$srcLen - 1] === '=') {
$srcLen--;
}
}
Expand All @@ -145,22 +145,22 @@ public static function decode(string $src, bool $strictPadding = false): string
'Incorrect padding'
);
}
if ($src[$srcLen - 1] === '=') {
if ($encodedString[$srcLen - 1] === '=') {
throw new \RangeException(
'Incorrect padding'
);
}
} else {
$src = \rtrim($src, '=');
$srcLen = Binary::safeStrlen($src);
$encodedString = \rtrim($encodedString, '=');
$srcLen = Binary::safeStrlen($encodedString);
}

$err = 0;
$dest = '';
// Main loop (no padding):
for ($i = 0; $i + 4 <= $srcLen; $i += 4) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C*', Binary::safeSubstr($src, $i, 4));
$chunk = \unpack('C*', Binary::safeSubstr($encodedString, $i, 4));
$c0 = static::decode6Bits($chunk[1]);
$c1 = static::decode6Bits($chunk[2]);
$c2 = static::decode6Bits($chunk[3]);
Expand All @@ -177,7 +177,7 @@ public static function decode(string $src, bool $strictPadding = false): string
// The last chunk, which may have padding:
if ($i < $srcLen) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C*', Binary::safeSubstr($src, $i, $srcLen - $i));
$chunk = \unpack('C*', Binary::safeSubstr($encodedString, $i, $srcLen - $i));
$c0 = static::decode6Bits($chunk[1]);

if ($i + 2 < $srcLen) {
Expand Down
2 changes: 1 addition & 1 deletion src/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function safeStrlen(string $str): int
if (\function_exists('mb_strlen')) {
return (int) \mb_strlen($str, '8bit');
} else {
return (int) \strlen($str);
return \strlen($str);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Hex.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public static function encodeUpper(string $binString): string
* Convert a hexadecimal string into a binary string without cache-timing
* leaks
*
* @param string $hexString
* @param string $encodedString
* @param bool $strictPadding
* @return string (raw binary)
* @throws \RangeException
*/
public static function decode(string $hexString, bool $strictPadding = false): string
public static function decode(string $encodedString, bool $strictPadding = false): string
{
/** @var int $hex_pos */
$hex_pos = 0;
Expand All @@ -111,7 +111,7 @@ public static function decode(string $hexString, bool $strictPadding = false): s
/** @var int $c_acc */
$c_acc = 0;
/** @var int $hex_len */
$hex_len = Binary::safeStrlen($hexString);
$hex_len = Binary::safeStrlen($encodedString);
/** @var int $state */
$state = 0;
if (($hex_len & 1) !== 0) {
Expand All @@ -120,13 +120,13 @@ public static function decode(string $hexString, bool $strictPadding = false): s
'Expected an even number of hexadecimal characters'
);
} else {
$hexString = '0' . $hexString;
$encodedString = '0' . $encodedString;
++$hex_len;
}
}

/** @var array<int, int> $chunk */
$chunk = \unpack('C*', $hexString);
$chunk = \unpack('C*', $encodedString);
while ($hex_pos < $hex_len) {
++$hex_pos;
/** @var int $c */
Expand Down

0 comments on commit 5e64617

Please sign in to comment.