Skip to content

Commit abf93d1

Browse files
committed
Move all exception codes to the ExceptionCodes class
1 parent bf7d6db commit abf93d1

5 files changed

+46
-46
lines changed

src/BeforeValidException.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
class BeforeValidException extends \UnexpectedValueException
66
{
7-
public const NBF_PRIOR_TO_DATE = 1;
8-
public const IAT_PRIOR_TO_DATE = 2;
97
}

src/ExceptionCodes.php

+42-38
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,50 @@ class ExceptionCodes
1212
public const EMPTY_ALGORITHM = 6;
1313
public const DECODE_ALGORITHM_NOT_SUPPORTED = 7;
1414
public const INCORRECT_KEY_FOR_ALGORITHM = 8;
15-
public const SIGN_ALGORITHM_NOT_SUPPORTED = 9;
16-
public const KEY_IS_NOT_STRING = 10;
17-
public const OPENSSL_CAN_NOT_SIGN_DATA = 11;
18-
public const SODIUM_KEY_IS_NOT_STRING = 12;
19-
public const SODIUM_EXCEPTION = 13;
20-
public const SIGN_GENERAL_EXCEPTION = 14;
21-
public const VERIFY_ALGORITHM_NOT_SUPPORTED = 15;
22-
public const VERIFY_OPEN_SSL_ERROR = 16;
23-
public const VERIFY_SODIUM_NOT_AVAILABLE = 17;
24-
public const VERIFY_KEY_MATERIAL_IS_NOT_STRING = 18;
25-
public const VERIFY_SODIUM_EXCEPTION = 19;
26-
public const VERIFY_KEY_IS_NOT_STRING = 20;
27-
public const DECODED_JSON_IS_NULL = 21;
28-
public const ENCODED_JSON_IS_NULL = 22;
29-
public const INVALID_JSON = 23;
30-
public const KID_IS_EMPTY = 24;
31-
public const KID_IS_INVALID = 25;
32-
public const JSON_ERROR = 26;
15+
public const SIGNATURE_VERIFICATION_FAILED = 9;
16+
public const NBF_PRIOR_TO_DATE = 10;
17+
public const IAT_PRIOR_TO_DATE = 11;
18+
public const TOKEN_EXPIRED = 12;
19+
public const SIGN_ALGORITHM_NOT_SUPPORTED = 13;
20+
public const KEY_IS_NOT_STRING = 14;
21+
public const OPENSSL_CAN_NOT_SIGN_DATA = 15;
22+
public const SODIUM_KEY_IS_NOT_STRING = 16;
23+
public const SODIUM_EXCEPTION = 17;
24+
public const SIGN_GENERAL_EXCEPTION = 18;
25+
public const VERIFY_ALGORITHM_NOT_SUPPORTED = 19;
26+
public const VERIFY_OPEN_SSL_ERROR = 20;
27+
public const VERIFY_SODIUM_NOT_AVAILABLE = 21;
28+
public const VERIFY_KEY_MATERIAL_IS_NOT_STRING = 22;
29+
public const VERIFY_SODIUM_EXCEPTION = 23;
30+
public const VERIFY_KEY_IS_NOT_STRING = 24;
31+
public const DECODED_JSON_IS_NULL = 25;
32+
public const ENCODED_JSON_IS_NULL = 26;
33+
public const INVALID_JSON = 27;
34+
public const KID_IS_EMPTY = 28;
35+
public const KID_IS_INVALID = 29;
36+
public const JSON_ERROR = 30;
3337

34-
public const KEY_ID_NOT_FOUND = 27;
35-
public const OFFSET_SET_METHOD_NOT_IMPLEMENTED = 28;
36-
public const OFFSET_UNSET_METHOD_NOT_IMPLEMENTED = 29;
38+
public const KEY_ID_NOT_FOUND = 31;
39+
public const OFFSET_SET_METHOD_NOT_IMPLEMENTED = 32;
40+
public const OFFSET_UNSET_METHOD_NOT_IMPLEMENTED = 33;
3741

38-
public const JWKS_URI_IS_EMPTY = 30;
42+
public const JWKS_URI_IS_EMPTY = 34;
3943

40-
public const JWK_MISSING_KEYS = 31;
41-
public const JWT_KEYS_IS_EMPTY = 32;
42-
public const JWT_ALGORITHM_NOT_SUPPORTED = 33;
43-
public const JWK_IS_EMPTY = 34;
44-
public const JWT_MISSING_KTY_PARAMETER = 35;
45-
public const JWT_MISSING_ALG_PARAMETER = 36;
46-
public const JWT_RSA_KEYS_NOT_SUPPORTED = 37;
47-
public const JWT_RSA_KEYS_MISSING_N_AND_E = 38;
48-
public const JWT_OPEN_SSL_ERROR = 39;
49-
public const JWK_EC_D_IS_NOT_SET = 40;
50-
public const JWT_EC_CRV_IS_EMPTY = 41;
51-
public const JWK_UNSUPPORTED_EC_CURVE = 42;
52-
public const JWT_X_AND_Y_ARE_EMPTY = 43;
44+
public const JWK_MISSING_KEYS = 35;
45+
public const JWT_KEYS_IS_EMPTY = 36;
46+
public const JWT_ALGORITHM_NOT_SUPPORTED = 37;
47+
public const JWK_IS_EMPTY = 38;
48+
public const JWT_MISSING_KTY_PARAMETER = 39;
49+
public const JWT_MISSING_ALG_PARAMETER = 40;
50+
public const JWT_RSA_KEYS_NOT_SUPPORTED = 41;
51+
public const JWT_RSA_KEYS_MISSING_N_AND_E = 42;
52+
public const JWT_OPEN_SSL_ERROR = 43;
53+
public const JWK_EC_D_IS_NOT_SET = 44;
54+
public const JWT_EC_CRV_IS_EMPTY = 45;
55+
public const JWK_UNSUPPORTED_EC_CURVE = 46;
56+
public const JWT_X_AND_Y_ARE_EMPTY = 47;
5357

54-
public const KEY_MATERIAL_IS_INVALID = 44;
55-
public const KEY_MATERIAL_IS_EMPTY = 45;
56-
public const KEY_ALGORITHM_IS_EMPTY = 46;
58+
public const KEY_MATERIAL_IS_INVALID = 48;
59+
public const KEY_MATERIAL_IS_EMPTY = 49;
60+
public const KEY_ALGORITHM_IS_EMPTY = 50;
5761
}

src/ExpiredException.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
class ExpiredException extends \UnexpectedValueException
66
{
7-
public const TOKEN_EXPIRED = 1;
87
}

src/JWT.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static function decode(
163163
if (!self::verify("${headb64}.${bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
164164
throw new SignatureInvalidException(
165165
'Signature verification failed',
166-
SignatureInvalidException::SIGNATURE_VERIFICATION_FAILED
166+
ExceptionCodes::SIGNATURE_VERIFICATION_FAILED
167167
);
168168
}
169169

@@ -172,7 +172,7 @@ public static function decode(
172172
if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {
173173
throw new BeforeValidException(
174174
'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->nbf),
175-
BeforeValidException::NBF_PRIOR_TO_DATE
175+
ExceptionCodes::NBF_PRIOR_TO_DATE
176176
);
177177
}
178178

@@ -182,13 +182,13 @@ public static function decode(
182182
if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {
183183
throw new BeforeValidException(
184184
'Cannot handle token prior to ' . \date(DateTime::ISO8601, $payload->iat),
185-
BeforeValidException::IAT_PRIOR_TO_DATE
185+
ExceptionCodes::IAT_PRIOR_TO_DATE
186186
);
187187
}
188188

189189
// Check if this token has expired.
190190
if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
191-
throw new ExpiredException('Expired token', ExpiredException::TOKEN_EXPIRED);
191+
throw new ExpiredException('Expired token', ExceptionCodes::TOKEN_EXPIRED);
192192
}
193193

194194
return $payload;

src/SignatureInvalidException.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
class SignatureInvalidException extends \UnexpectedValueException
66
{
7-
public const SIGNATURE_VERIFICATION_FAILED = 1;
87
}

0 commit comments

Comments
 (0)