summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/JWT.php42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/JWT.php b/src/JWT.php
index 0e61368..6d30e94 100644
--- a/src/JWT.php
+++ b/src/JWT.php
@@ -66,7 +66,7 @@ class JWT
*/
public static function decode($jwt, $key, $allowed_algs = array())
{
- $timestamp = is_null(self::$timestamp) ? time() : self::$timestamp;
+ $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp;
if (empty($key)) {
throw new InvalidArgumentException('Key may not be empty');
@@ -79,18 +79,18 @@ class JWT
throw new UnexpectedValueException('Wrong number of segments');
}
list($headb64, $bodyb64, $cryptob64) = $tks;
- if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {
+ if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) {
throw new UnexpectedValueException('Invalid header encoding');
}
- if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {
+ if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) {
throw new UnexpectedValueException('Invalid claims encoding');
}
- $sig = JWT::urlsafeB64Decode($cryptob64);
+ $sig = static::urlsafeB64Decode($cryptob64);
if (empty($header->alg)) {
throw new UnexpectedValueException('Empty algorithm');
}
- if (empty(self::$supported_algs[$header->alg])) {
+ if (empty(static::$supported_algs[$header->alg])) {
throw new UnexpectedValueException('Algorithm not supported');
}
if (!in_array($header->alg, $allowed_algs)) {
@@ -105,13 +105,13 @@ class JWT
}
// Check the signature
- if (!JWT::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
+ if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
throw new SignatureInvalidException('Signature verification failed');
}
// Check if the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
- if (isset($payload->nbf) && $payload->nbf > ($timestamp + self::$leeway)) {
+ if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf)
);
@@ -120,14 +120,14 @@ class JWT
// Check that this token has been created before 'now'. This prevents
// using tokens that have been created for later use (and haven't
// correctly used the nbf claim).
- if (isset($payload->iat) && $payload->iat > ($timestamp + self::$leeway)) {
+ if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);
}
// Check if this token has expired.
- if (isset($payload->exp) && ($timestamp - self::$leeway) >= $payload->exp) {
+ if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
throw new ExpiredException('Expired token');
}
@@ -160,12 +160,12 @@ class JWT
$header = array_merge($head, $header);
}
$segments = array();
- $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
- $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
+ $segments[] = static::urlsafeB64Encode(static::jsonEncode($header));
+ $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload));
$signing_input = implode('.', $segments);
- $signature = JWT::sign($signing_input, $key, $alg);
- $segments[] = JWT::urlsafeB64Encode($signature);
+ $signature = static::sign($signing_input, $key, $alg);
+ $segments[] = static::urlsafeB64Encode($signature);
return implode('.', $segments);
}
@@ -184,10 +184,10 @@ class JWT
*/
public static function sign($msg, $key, $alg = 'HS256')
{
- if (empty(self::$supported_algs[$alg])) {
+ if (empty(static::$supported_algs[$alg])) {
throw new DomainException('Algorithm not supported');
}
- list($function, $algorithm) = self::$supported_algs[$alg];
+ list($function, $algorithm) = static::$supported_algs[$alg];
switch($function) {
case 'hash_hmac':
return hash_hmac($algorithm, $msg, $key, true);
@@ -217,11 +217,11 @@ class JWT
*/
private static function verify($msg, $signature, $key, $alg)
{
- if (empty(self::$supported_algs[$alg])) {
+ if (empty(static::$supported_algs[$alg])) {
throw new DomainException('Algorithm not supported');
}
- list($function, $algorithm) = self::$supported_algs[$alg];
+ list($function, $algorithm) = static::$supported_algs[$alg];
switch($function) {
case 'openssl':
$success = openssl_verify($msg, $signature, $key, $algorithm);
@@ -236,13 +236,13 @@ class JWT
if (function_exists('hash_equals')) {
return hash_equals($signature, $hash);
}
- $len = min(self::safeStrlen($signature), self::safeStrlen($hash));
+ $len = min(static::safeStrlen($signature), static::safeStrlen($hash));
$status = 0;
for ($i = 0; $i < $len; $i++) {
$status |= (ord($signature[$i]) ^ ord($hash[$i]));
}
- $status |= (self::safeStrlen($signature) ^ self::safeStrlen($hash));
+ $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash));
return ($status === 0);
}
@@ -276,7 +276,7 @@ class JWT
}
if (function_exists('json_last_error') && $errno = json_last_error()) {
- JWT::handleJsonError($errno);
+ static::handleJsonError($errno);
} elseif ($obj === null && $input !== 'null') {
throw new DomainException('Null result with non-null input');
}
@@ -296,7 +296,7 @@ class JWT
{
$json = json_encode($input);
if (function_exists('json_last_error') && $errno = json_last_error()) {
- JWT::handleJsonError($errno);
+ static::handleJsonError($errno);
} elseif ($json === 'null' && $input !== null) {
throw new DomainException('Null result with non-null input');
}