Unverified Commit f49da04f authored by P.I.E. Security Team's avatar P.I.E. Security Team Committed by GitHub
Browse files

Merge pull request #37 from paragonie/v2-cleanup

Clean up unnecessary annotations
No related merge requests found
Showing with 3 additions and 23 deletions
+3 -23
......@@ -367,7 +367,6 @@ abstract class Base32 implements EncoderInterface
$err |= ($c0) >> 8;
}
}
/** @var bool $check */
$check = ($err === 0);
if (!$check) {
throw new \RangeException(
......
......@@ -196,11 +196,10 @@ abstract class Base64 implements EncoderInterface
((($c0 << 2) | ($c1 >> 4)) & 0xff)
);
$err |= ($c0 | $c1) >> 8;
} elseif ($i < $srcLen && $strictPadding) {
} elseif ($strictPadding) {
$err |= 1;
}
}
/** @var bool $check */
$check = ($err === 0);
if (!$check) {
throw new \RangeException(
......
......@@ -62,14 +62,14 @@ abstract class Binary
* @staticvar boolean $exists
* @param string $str
* @param int $start
* @param int $length
* @param ?int $length
* @return string
* @throws \TypeError
*/
public static function safeSubstr(
string $str,
int $start = 0,
$length = null
int $length = null
): string {
if ($length === 0) {
return '';
......
......@@ -41,15 +41,12 @@ abstract class Hex implements EncoderInterface
*/
public static function encode(string $binString): string
{
/** @var string $hex */
$hex = '';
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 1));
/** @var int $c */
$c = $chunk[1] & 0xf;
/** @var int $b */
$b = $chunk[1] >> 4;
$hex .= pack(
......@@ -71,17 +68,13 @@ abstract class Hex implements EncoderInterface
*/
public static function encodeUpper(string $binString): string
{
/** @var string $hex */
$hex = '';
/** @var int $len */
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 2));
/** @var int $c */
$c = $chunk[1] & 0xf;
/** @var int $b */
$b = $chunk[1] >> 4;
$hex .= pack(
......@@ -104,15 +97,10 @@ abstract class Hex implements EncoderInterface
*/
public static function decode(string $encodedString, bool $strictPadding = false): string
{
/** @var int $hex_pos */
$hex_pos = 0;
/** @var string $bin */
$bin = '';
/** @var int $c_acc */
$c_acc = 0;
/** @var int $hex_len */
$hex_len = Binary::safeStrlen($encodedString);
/** @var int $state */
$state = 0;
if (($hex_len & 1) !== 0) {
if ($strictPadding) {
......@@ -129,15 +117,10 @@ abstract class Hex implements EncoderInterface
$chunk = \unpack('C*', $encodedString);
while ($hex_pos < $hex_len) {
++$hex_pos;
/** @var int $c */
$c = $chunk[$hex_pos];
/** @var int $c_num */
$c_num = $c ^ 48;
/** @var int $c_num0 */
$c_num0 = ($c_num - 10) >> 8;
/** @var int $c_alpha */
$c_alpha = ($c & ~32) - 55;
/** @var int $c_alpha0 */
$c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8;
if (($c_num0 | $c_alpha0) === 0) {
......@@ -145,7 +128,6 @@ abstract class Hex implements EncoderInterface
'Expected hexadecimal character'
);
}
/** @var int $c_val */
$c_val = ($c_num0 & $c_num) | ($c_alpha & $c_alpha0);
if ($state === 0) {
$c_acc = $c_val * 16;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment