Remove all the {{{ and }}} folding
This commit is contained in:
20
src/Jwt.php
20
src/Jwt.php
@@ -16,7 +16,6 @@ namespace Domframework;
|
||||
class Jwt
|
||||
{
|
||||
// PROPERTIES
|
||||
// {{{
|
||||
/** List the allowed algorithms to sign the token
|
||||
*/
|
||||
private $supportedAlgs = array (
|
||||
@@ -24,7 +23,6 @@ class Jwt
|
||||
'HS512' => array('hash_hmac', 'SHA512'),
|
||||
'HS384' => array('hash_hmac', 'SHA384'),
|
||||
);
|
||||
// }}}
|
||||
|
||||
/** Create the token based on payload, sign it with key, and optionally
|
||||
* encrypt it with ckey
|
||||
@@ -42,7 +40,6 @@ class Jwt
|
||||
*/
|
||||
public function encode ($payload, $key, $alg = "HS256", $ckey = null,
|
||||
$cipherMethod = "des-ede3-cbc")
|
||||
// {{{
|
||||
{
|
||||
if (! key_exists ($alg, $this->supportedAlgs))
|
||||
throw new \Exception (dgettext ("domframework",
|
||||
@@ -62,7 +59,6 @@ class Jwt
|
||||
$segments[] = $this->urlsafeB64Encode ($signature);
|
||||
return implode ('.', $segments);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Decode the provide JWT and return an array of the payload
|
||||
* @param string $jwt The token to examine
|
||||
@@ -78,7 +74,6 @@ class Jwt
|
||||
*/
|
||||
public function decode ($jwt, $key, $allowedAlg = null, $ckey = null,
|
||||
$cipherMethod = "des-ede3-cbc")
|
||||
// {{{
|
||||
{
|
||||
if ($allowedAlg === null)
|
||||
$allowedAlg = array_keys ($this->supportedAlgs);
|
||||
@@ -126,7 +121,6 @@ class Jwt
|
||||
"JWT Signature verification failed"), 403);
|
||||
return $payload;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Verify the provided token with the key and generate an return true if it
|
||||
* can be verify
|
||||
@@ -137,7 +131,6 @@ class Jwt
|
||||
* @return boolean Return true if the input signed is valid
|
||||
*/
|
||||
private function verify ($input, $sign, $key, $alg)
|
||||
// {{{
|
||||
{
|
||||
$signature = $this->sign ($input, $key, $alg);
|
||||
if (function_exists ("hash_equals") &&
|
||||
@@ -151,17 +144,14 @@ class Jwt
|
||||
$status |= ord ($signature[$i]) ^ ord ($sign[$i]);
|
||||
return $status === 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Create a signing key
|
||||
* @return string the signing key proposed
|
||||
*/
|
||||
public function createKey ()
|
||||
// {{{
|
||||
{
|
||||
return sha1 (microtime (true));
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Sign the requested string with the provided key and based on the algorithm
|
||||
* @param string $input The string to sign
|
||||
@@ -170,7 +160,6 @@ class Jwt
|
||||
* @return string The signed string in binary
|
||||
*/
|
||||
private function sign ($input, $key, $alg)
|
||||
// {{{
|
||||
{
|
||||
if (! key_exists ($alg, $this->supportedAlgs))
|
||||
throw new \Exception (dgettext ("domframework",
|
||||
@@ -185,7 +174,6 @@ class Jwt
|
||||
"Invalid method to sign the JWT"), 500);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the provided string in base64 without equal at the end
|
||||
* To be URL compliant, the slash and plus are converted to underscore and
|
||||
@@ -194,18 +182,15 @@ class Jwt
|
||||
* @return string The string converted in base64
|
||||
*/
|
||||
private function urlsafeB64Encode ($str)
|
||||
// {{{
|
||||
{
|
||||
return rtrim (strtr (base64_encode ($str), '+/', '-_'), "=");
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the provided base64 to string
|
||||
* @param string $str The string the convert from base64
|
||||
* @return string The string converted from base64
|
||||
*/
|
||||
private function urlsafeB64Decode ($str)
|
||||
// {{{
|
||||
{
|
||||
$str = strtr ($str, '-_', '+/');
|
||||
$remainder = strlen ($str) % 4;
|
||||
@@ -219,14 +204,12 @@ class Jwt
|
||||
}
|
||||
return base64_decode ($str);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Return the provided array to JSON string
|
||||
* @param object $input The object to convert in JSON
|
||||
* @return string The JSON string
|
||||
*/
|
||||
private function jsonEncode ($input)
|
||||
// {{{
|
||||
{
|
||||
$json = json_encode ($input);
|
||||
if ($json === "null" && $input !== null)
|
||||
@@ -234,7 +217,6 @@ class Jwt
|
||||
"JSON Encode : Null result with non-null input"), 500);
|
||||
return $json;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Decode the provided JSON string and return the result
|
||||
* If null, there is a decode problem
|
||||
@@ -242,9 +224,7 @@ class Jwt
|
||||
* @return mixed The decoded string in object
|
||||
*/
|
||||
private function jsonDecode ($input)
|
||||
// {{{
|
||||
{
|
||||
return json_decode ($input, false, 512, JSON_BIGINT_AS_STRING);
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user