},
{
"name": "paragonie/constant_time_encoding",
- "version": "v2.5.0",
+ "version": "v2.6.3",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
- "reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8"
+ "reference": "58c3f47f650c94ec05a151692652a868995d2938"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/9229e15f2e6ba772f0c55dd6986c563b937170a8",
- "reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8",
+ "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938",
+ "reference": "58c3f47f650c94ec05a151692652a868995d2938",
"shasum": ""
},
"require": {
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
"source": "https://github.com/paragonie/constant_time_encoding"
},
- "time": "2022-01-17T05:32:27+00:00"
+ "time": "2022-06-14T06:56:20+00:00"
},
{
"name": "pear/net_idna2",
},
{
"name": "paragonie/constant_time_encoding",
- "version": "v2.5.0",
- "version_normalized": "2.5.0.0",
+ "version": "v2.6.3",
+ "version_normalized": "2.6.3.0",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
- "reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8"
+ "reference": "58c3f47f650c94ec05a151692652a868995d2938"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/9229e15f2e6ba772f0c55dd6986c563b937170a8",
- "reference": "9229e15f2e6ba772f0c55dd6986c563b937170a8",
+ "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938",
+ "reference": "58c3f47f650c94ec05a151692652a868995d2938",
"shasum": ""
},
"require": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^1|^2|^3|^4"
},
- "time": "2022-01-17T05:32:27+00:00",
+ "time": "2022-06-14T06:56:20+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
'dev_requirement' => false,
),
'paragonie/constant_time_encoding' => array(
- 'pretty_version' => 'v2.5.0',
- 'version' => '2.5.0.0',
+ 'pretty_version' => 'v2.6.3',
+ 'version' => '2.6.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../paragonie/constant_time_encoding',
'aliases' => array(),
- 'reference' => '9229e15f2e6ba772f0c55dd6986c563b937170a8',
+ 'reference' => '58c3f47f650c94ec05a151692652a868995d2938',
'dev_requirement' => false,
),
'pear/net_idna2' => array(
+++ /dev/null
-# Path-based git attributes
-# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
-
-# This way, the files would be available in the repository but it would not be downloaded when the package is required by another project.
-/.github export-ignore
-/.gitignore export-ignore
-/tests export-ignore
-/phpunit.xml.dist export-ignore
-/psalm.xml export-ignore
"psr-4": {
"ParagonIE\\ConstantTime\\": "src/"
}
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "ParagonIE\\ConstantTime\\Tests\\": "tests/"
+ }
}
}
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use InvalidArgumentException;
+use RangeException;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*
* @param string $binString
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encode(string $binString): string
{
*
* @param string $src
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encodeUnpadded(string $src): string
{
*
* @param string $src
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encodeUpper(string $src): string
{
*
* @param string $src
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encodeUpperUnpadded(string $src): string
{
return \pack('C', $src + $diff);
}
+ /**
+ * @param string $encodedString
+ * @param bool $upper
+ * @return string
+ */
+ public static function decodeNoPadding(string $encodedString, bool $upper = false): string
+ {
+ $srcLen = Binary::safeStrlen($encodedString);
+ if ($srcLen === 0) {
+ return '';
+ }
+ if (($srcLen & 7) === 0) {
+ for ($j = 0; $j < 7 && $j < $srcLen; ++$j) {
+ if ($encodedString[$srcLen - $j - 1] === '=') {
+ throw new InvalidArgumentException(
+ "decodeNoPadding() doesn't tolerate padding"
+ );
+ }
+ }
+ }
+ return static::doDecode(
+ $encodedString,
+ $upper,
+ true
+ );
+ }
/**
* Base32 decoding
* @param bool $upper
* @param bool $strictPadding
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
* @psalm-suppress RedundantCondition
*/
- protected static function doDecode(string $src, bool $upper = false, bool $strictPadding = false): string
- {
+ protected static function doDecode(
+ string $src,
+ bool $upper = false,
+ bool $strictPadding = false
+ ): string {
// We do this to reduce code duplication:
$method = $upper
? 'decode5BitsUpper'
}
}
if (($srcLen & 7) === 1) {
- throw new \RangeException(
+ throw new RangeException(
'Incorrect padding'
);
}
(($c4 << 7) | ($c5 << 2) | ($c6 >> 3)) & 0xff
);
$err |= ($c0 | $c1 | $c2 | $c3 | $c4 | $c5 | $c6) >> 8;
+ if ($strictPadding) {
+ $err |= ($c6 << 5) & 0xff;
+ }
} elseif ($i + 5 < $srcLen) {
/** @var int $c1 */
$c1 = static::$method($chunk[2]);
(($c3 << 4) | ($c4 >> 1) ) & 0xff
);
$err |= ($c0 | $c1 | $c2 | $c3 | $c4) >> 8;
+ if ($strictPadding) {
+ $err |= ($c4 << 7) & 0xff;
+ }
} elseif ($i + 3 < $srcLen) {
/** @var int $c1 */
$c1 = static::$method($chunk[2]);
(($c1 << 6) | ($c2 << 1) | ($c3 >> 4)) & 0xff
);
$err |= ($c0 | $c1 | $c2 | $c3) >> 8;
+ if ($strictPadding) {
+ $err |= ($c3 << 4) & 0xff;
+ }
} elseif ($i + 2 < $srcLen) {
/** @var int $c1 */
$c1 = static::$method($chunk[2]);
(($c1 << 6) | ($c2 << 1) ) & 0xff
);
$err |= ($c0 | $c1 | $c2) >> 8;
+ if ($strictPadding) {
+ $err |= ($c2 << 6) & 0xff;
+ }
} elseif ($i + 1 < $srcLen) {
/** @var int $c1 */
$c1 = static::$method($chunk[2]);
(($c0 << 3) | ($c1 >> 2) ) & 0xff
);
$err |= ($c0 | $c1) >> 8;
+ if ($strictPadding) {
+ $err |= ($c1 << 6) & 0xff;
+ }
} else {
$dest .= \pack(
'C',
}
$check = ($err === 0);
if (!$check) {
- throw new \RangeException(
+ throw new RangeException(
'Base32::doDecode() only expects characters in the correct base32 alphabet'
);
}
* @param bool $upper
* @param bool $pad
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
protected static function doEncode(string $src, bool $upper = false, $pad = true): string
{
namespace ParagonIE\ConstantTime;
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use InvalidArgumentException;
+use RangeException;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*
* @param string $binString
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function encode(string $binString): string
{
*
* @param string $src
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function encodeUnpadded(string $src): string
{
* @param string $src
* @param bool $pad Include = padding?
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
protected static function doEncode(string $src, bool $pad = true): string
{
* @param string $encodedString
* @param bool $strictPadding
* @return string
- * @throws \RangeException
- * @throws \TypeError
+ *
+ * @throws RangeException
+ * @throws TypeError
* @psalm-suppress RedundantCondition
*/
public static function decode(string $encodedString, bool $strictPadding = false): string
}
}
if (($srcLen & 3) === 1) {
- throw new \RangeException(
+ throw new RangeException(
'Incorrect padding'
);
}
if ($encodedString[$srcLen - 1] === '=') {
- throw new \RangeException(
+ throw new RangeException(
'Incorrect padding'
);
}
((($c1 << 4) | ($c2 >> 2)) & 0xff)
);
$err |= ($c0 | $c1 | $c2) >> 8;
+ if ($strictPadding) {
+ $err |= ($c2 << 6) & 0xff;
+ }
} elseif ($i + 1 < $srcLen) {
$c1 = static::decode6Bits($chunk[2]);
$dest .= \pack(
((($c0 << 2) | ($c1 >> 4)) & 0xff)
);
$err |= ($c0 | $c1) >> 8;
+ if ($strictPadding) {
+ $err |= ($c1 << 4) & 0xff;
+ }
} elseif ($strictPadding) {
$err |= 1;
}
}
$check = ($err === 0);
if (!$check) {
- throw new \RangeException(
+ throw new RangeException(
'Base64::decode() only expects characters in the correct base64 alphabet'
);
}
return $dest;
}
+ /**
+ * @param string $encodedString
+ * @return string
+ */
+ public static function decodeNoPadding(string $encodedString): string
+ {
+ $srcLen = Binary::safeStrlen($encodedString);
+ if ($srcLen === 0) {
+ return '';
+ }
+ if (($srcLen & 3) === 0) {
+ if ($encodedString[$srcLen - 1] === '=') {
+ throw new InvalidArgumentException(
+ "decodeNoPadding() doesn't tolerate padding"
+ );
+ }
+ if (($srcLen & 3) > 1) {
+ if ($encodedString[$srcLen - 2] === '=') {
+ throw new InvalidArgumentException(
+ "decodeNoPadding() doesn't tolerate padding"
+ );
+ }
+ }
+ }
+ return static::decode(
+ $encodedString,
+ true
+ );
+ }
+
/**
* Uses bitwise operators instead of table-lookups to turn 6-bit integers
* into 8-bit integers.
namespace ParagonIE\ConstantTime;
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
namespace ParagonIE\ConstantTime;
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
namespace ParagonIE\ConstantTime;
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* @param int $start
* @param ?int $length
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function safeSubstr(
string $str,
namespace ParagonIE\ConstantTime;
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32Encode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32EncodeUpper(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32Decode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32DecodeUpper(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32HexEncode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32HexEncodeUpper(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32HexDecode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base32HexDecodeUpper(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64Encode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64Decode(string $str): string
{
* Base64 character set "./[A-Z][a-z][0-9]"
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64EncodeDotSlash(string $str): string
{
* @param string $str
* @return string
* @throws \RangeException
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64DecodeDotSlash(string $str): string
{
* Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
* @param string $str
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64EncodeDotSlashOrdered(string $str): string
{
* @param string $str
* @return string
* @throws \RangeException
- * @throws \TypeError
+ * @throws TypeError
*/
public static function base64DecodeDotSlashOrdered(string $str): string
{
*
* @param string $bin_string (raw binary)
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function hexEncode(string $bin_string): string
{
*
* @param string $bin_string (raw binary)
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function hexEncodeUpper(string $bin_string): string
{
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use RangeException;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*
* @param string $binString (raw binary)
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encode(string $binString): string
{
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
- $chunk = \unpack('C', Binary::safeSubstr($binString, $i, 1));
+ $chunk = \unpack('C', $binString[$i]);
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
- $hex .= pack(
+ $hex .= \pack(
'CC',
(87 + $b + ((($b - 10) >> 8) & ~38)),
(87 + $c + ((($c - 10) >> 8) & ~38))
*
* @param string $binString (raw binary)
* @return string
- * @throws \TypeError
+ * @throws TypeError
*/
public static function encodeUpper(string $binString): string
{
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
- $chunk = \unpack('C', Binary::safeSubstr($binString, $i, 2));
+ $chunk = \unpack('C', $binString[$i]);
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
- $hex .= pack(
+ $hex .= \pack(
'CC',
(55 + $b + ((($b - 10) >> 8) & ~6)),
(55 + $c + ((($c - 10) >> 8) & ~6))
* @param string $encodedString
* @param bool $strictPadding
* @return string (raw binary)
- * @throws \RangeException
+ * @throws RangeException
*/
- public static function decode(string $encodedString, bool $strictPadding = false): string
- {
+ public static function decode(
+ string $encodedString,
+ bool $strictPadding = false
+ ): string {
$hex_pos = 0;
$bin = '';
$c_acc = 0;
$state = 0;
if (($hex_len & 1) !== 0) {
if ($strictPadding) {
- throw new \RangeException(
+ throw new RangeException(
'Expected an even number of hexadecimal characters'
);
} else {
$c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8;
if (($c_num0 | $c_alpha0) === 0) {
- throw new \RangeException(
+ throw new RangeException(
'Expected hexadecimal character'
);
}
declare(strict_types=1);
namespace ParagonIE\ConstantTime;
+use TypeError;
+
/**
- * Copyright (c) 2016 - 2018 Paragon Initiative Enterprises.
+ * Copyright (c) 2016 - 2022 Paragon Initiative Enterprises.
* Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base64Encode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base64Decode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base64UrlSafeEncode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base64UrlSafeDecode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base32Encode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base32Decode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base32HexEncode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base32HexDecode(string $str): string
{
*
* @param string $str
* @return string
- * @throws \TypeError
+ *
+ * @throws TypeError
*/
public static function base16Encode(string $str): string
{