Skip to content

Commit

Permalink
Fix pastos and docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Jan 23, 2018
1 parent 61083df commit 7c74c5d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 28 deletions.
8 changes: 8 additions & 0 deletions src/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class Base32 implements EncoderInterface
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function decode(string $src, bool $strictPadding = false): string
{
Expand All @@ -49,6 +50,7 @@ public static function decode(string $src, bool $strictPadding = false): string
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function decodeUpper(string $src, bool $strictPadding = false): string
{
Expand All @@ -60,6 +62,7 @@ public static function decodeUpper(string $src, bool $strictPadding = false): st
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function encode(string $src): string
{
Expand All @@ -70,6 +73,7 @@ public static function encode(string $src): string
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function encodeUnpadded(string $src): string
{
Expand All @@ -81,6 +85,7 @@ public static function encodeUnpadded(string $src): string
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function encodeUpper(string $src): string
{
Expand All @@ -92,6 +97,7 @@ public static function encodeUpper(string $src): string
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function encodeUpperUnpadded(string $src): string
{
Expand Down Expand Up @@ -184,6 +190,7 @@ protected static function encode5BitsUpper(int $src): string
* @param bool $upper
* @param bool $strictPadding
* @return string
* @throws \TypeError
*/
protected static function doDecode(string $src, bool $upper = false, bool $strictPadding = false): string
{
Expand Down Expand Up @@ -342,6 +349,7 @@ protected static function doDecode(string $src, bool $upper = false, bool $stric
* @param bool $upper
* @param bool $pad
* @return string
* @throws \TypeError
*/
protected static function doEncode(string $src, bool $upper = false, $pad = true): string
{
Expand Down
3 changes: 3 additions & 0 deletions src/Base64.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static function encode(string $src): string
*
* @param string $src
* @return string
* @throws \TypeError
*/
public static function encodeUnpadded(string $src): string
{
Expand All @@ -63,6 +64,7 @@ public static function encodeUnpadded(string $src): string
* @param string $src
* @param bool $pad Include = padding?
* @return string
* @throws \TypeError
*/
protected static function doEncode(string $src, bool $pad = true): string
{
Expand Down Expand Up @@ -115,6 +117,7 @@ protected static function doEncode(string $src, bool $pad = true): string
* @param bool $strictPadding
* @return string
* @throws \RangeException
* @throws \TypeError
*/
public static function decode(string $src, bool $strictPadding = false): string
{
Expand Down
50 changes: 31 additions & 19 deletions src/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ abstract class Encoding
/**
* RFC 4648 Base32 encoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32Encode(string $str): string
{
Expand All @@ -45,8 +46,9 @@ public static function base32Encode(string $str): string
/**
* RFC 4648 Base32 encoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32EncodeUpper(string $str): string
{
Expand All @@ -56,8 +58,9 @@ public static function base32EncodeUpper(string $str): string
/**
* RFC 4648 Base32 decoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32Decode(string $str): string
{
Expand All @@ -67,8 +70,9 @@ public static function base32Decode(string $str): string
/**
* RFC 4648 Base32 decoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32DecodeUpper(string $str): string
{
Expand All @@ -78,42 +82,45 @@ public static function base32DecodeUpper(string $str): string
/**
* RFC 4648 Base32 encoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32HexEncode(string $str): string
{
return Base32Hex::encode($str);
}


/**
* RFC 4648 Base32 encoding
* RFC 4648 Base32Hex encoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32HexEncodeUpper(string $str): string
{
return Base32Hex::encodeUpper($str);
}

/**
* RFC 4648 Base32 decoding
* RFC 4648 Base32Hex decoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32HexDecode(string $str): string
{
return Base32Hex::decode($str);
}

/**
* RFC 4648 Base32 decoding
* RFC 4648 Base32Hex decoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base32HexDecodeUpper(string $str): string
{
Expand All @@ -123,7 +130,7 @@ public static function base32HexDecodeUpper(string $str): string
/**
* RFC 4648 Base64 encoding
*
* @param $str
* @param string $str
* @return string
*/
public static function base64Encode(string $str): string
Expand All @@ -132,10 +139,11 @@ public static function base64Encode(string $str): string
}

/**
* RFC 4648 Base32 decoding
* RFC 4648 Base64 decoding
*
* @param $str
* @param string $str
* @return string
* @throws \TypeError
*/
public static function base64Decode(string $str): string
{
Expand All @@ -146,7 +154,7 @@ public static function base64Decode(string $str): string
* Encode into Base64
*
* Base64 character set "./[A-Z][a-z][0-9]"
* @param $src
* @param string $str
* @return string
*/
public static function base64EncodeDotSlash(string $str): string
Expand All @@ -159,9 +167,10 @@ public static function base64EncodeDotSlash(string $str): string
*
* Base64 character set "./[A-Z][a-z][0-9]"
*
* @param $src
* @param string $str
* @return string
* @throws \RangeException
* @throws \TypeError
*/
public static function base64DecodeDotSlash(string $str): string
{
Expand All @@ -172,7 +181,7 @@ public static function base64DecodeDotSlash(string $str): string
* Encode into Base64
*
* Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
* @param $src
* @param string $str
* @return string
*/
public static function base64EncodeDotSlashOrdered(string $str): string
Expand All @@ -185,9 +194,10 @@ public static function base64EncodeDotSlashOrdered(string $str): string
*
* Base64 character set "[.-9][A-Z][a-z]" or "./[0-9][A-Z][a-z]"
*
* @param $src
* @param string $str
* @return string
* @throws \RangeException
* @throws \TypeError
*/
public static function base64DecodeDotSlashOrdered(string $str): string
{
Expand All @@ -200,6 +210,7 @@ public static function base64DecodeDotSlashOrdered(string $str): string
*
* @param string $bin_string (raw binary)
* @return string
* @throws \TypeError
*/
public static function hexEncode(string $bin_string): string
{
Expand All @@ -225,6 +236,7 @@ public static function hexDecode(string $hex_string): string
*
* @param string $bin_string (raw binary)
* @return string
* @throws \TypeError
*/
public static function hexEncodeUpper(string $bin_string): string
{
Expand Down
20 changes: 11 additions & 9 deletions src/Hex.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ abstract class Hex implements EncoderInterface
* Convert a binary string into a hexadecimal string without cache-timing
* leaks
*
* @param string $bin_string (raw binary)
* @param string $binString (raw binary)
* @return string
* @throws \TypeError
*/
public static function encode(string $bin_string): string
public static function encode(string $binString): string
{
$hex = '';
$len = Binary::safeStrlen($bin_string);
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
$chunk = \unpack('C', Binary::safeSubstr($bin_string, $i, 2));
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 1));
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
$hex .= pack(
Expand All @@ -59,15 +60,16 @@ public static function encode(string $bin_string): string
* Convert a binary string into a hexadecimal string without cache-timing
* leaks, returning uppercase letters (as per RFC 4648)
*
* @param string $bin_string (raw binary)
* @param string $binString (raw binary)
* @return string
* @throws \TypeError
*/
public static function encodeUpper(string $bin_string): string
public static function encodeUpper(string $binString): string
{
$hex = '';
$len = Binary::safeStrlen($bin_string);
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
$chunk = \unpack('C', Binary::safeSubstr($bin_string, $i, 2));
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 2));
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
$hex .= pack(
Expand All @@ -83,7 +85,7 @@ public static function encodeUpper(string $bin_string): string
* Convert a hexadecimal string into a binary string without cache-timing
* leaks
*
* @param string $hex_string
* @param string $hexString
* @param bool $strictPadding
* @return string (raw binary)
* @throws \RangeException
Expand Down
7 changes: 7 additions & 0 deletions src/RFC4648.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function base64Encode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base64Decode(string $str): string
{
Expand All @@ -80,6 +81,7 @@ public function base64UrlSafeEncode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base64UrlSafeDecode(string $str): string
{
Expand All @@ -93,6 +95,7 @@ public function base64UrlSafeDecode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base32Encode(string $str): string
{
Expand All @@ -106,6 +109,7 @@ public function base32Encode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base32Decode(string $str): string
{
Expand All @@ -119,6 +123,7 @@ public function base32Decode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base32HexEncode(string $str): string
{
Expand All @@ -132,6 +137,7 @@ public function base32HexEncode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base32HexDecode(string $str): string
{
Expand All @@ -145,6 +151,7 @@ public function base32HexDecode(string $str): string
*
* @param string $str
* @return string
* @throws \TypeError
*/
public function base16Encode(string $str): string
{
Expand Down

0 comments on commit 7c74c5d

Please sign in to comment.