@@ -66,7 +66,7 @@ class JWT
66
66
*/
67
67
public static function decode ($ jwt , $ key , $ allowed_algs = array ())
68
68
{
69
- $ timestamp = is_null (self ::$ timestamp ) ? time () : self ::$ timestamp ;
69
+ $ timestamp = is_null (static ::$ timestamp ) ? time () : static ::$ timestamp ;
70
70
71
71
if (empty ($ key )) {
72
72
throw new InvalidArgumentException ('Key may not be empty ' );
@@ -79,18 +79,18 @@ public static function decode($jwt, $key, $allowed_algs = array())
79
79
throw new UnexpectedValueException ('Wrong number of segments ' );
80
80
}
81
81
list ($ headb64 , $ bodyb64 , $ cryptob64 ) = $ tks ;
82
- if (null === ($ header = JWT ::jsonDecode (JWT ::urlsafeB64Decode ($ headb64 )))) {
82
+ if (null === ($ header = static ::jsonDecode (static ::urlsafeB64Decode ($ headb64 )))) {
83
83
throw new UnexpectedValueException ('Invalid header encoding ' );
84
84
}
85
- if (null === $ payload = JWT ::jsonDecode (JWT ::urlsafeB64Decode ($ bodyb64 ))) {
85
+ if (null === $ payload = static ::jsonDecode (static ::urlsafeB64Decode ($ bodyb64 ))) {
86
86
throw new UnexpectedValueException ('Invalid claims encoding ' );
87
87
}
88
- $ sig = JWT ::urlsafeB64Decode ($ cryptob64 );
88
+ $ sig = static ::urlsafeB64Decode ($ cryptob64 );
89
89
90
90
if (empty ($ header ->alg )) {
91
91
throw new UnexpectedValueException ('Empty algorithm ' );
92
92
}
93
- if (empty (self ::$ supported_algs [$ header ->alg ])) {
93
+ if (empty (static ::$ supported_algs [$ header ->alg ])) {
94
94
throw new UnexpectedValueException ('Algorithm not supported ' );
95
95
}
96
96
if (!in_array ($ header ->alg , $ allowed_algs )) {
@@ -105,13 +105,13 @@ public static function decode($jwt, $key, $allowed_algs = array())
105
105
}
106
106
107
107
// Check the signature
108
- if (!JWT ::verify ("$ headb64. $ bodyb64 " , $ sig , $ key , $ header ->alg )) {
108
+ if (!static ::verify ("$ headb64. $ bodyb64 " , $ sig , $ key , $ header ->alg )) {
109
109
throw new SignatureInvalidException ('Signature verification failed ' );
110
110
}
111
111
112
112
// Check if the nbf if it is defined. This is the time that the
113
113
// token can actually be used. If it's not yet that time, abort.
114
- if (isset ($ payload ->nbf ) && $ payload ->nbf > ($ timestamp + self ::$ leeway )) {
114
+ if (isset ($ payload ->nbf ) && $ payload ->nbf > ($ timestamp + static ::$ leeway )) {
115
115
throw new BeforeValidException (
116
116
'Cannot handle token prior to ' . date (DateTime::ISO8601 , $ payload ->nbf )
117
117
);
@@ -120,14 +120,14 @@ public static function decode($jwt, $key, $allowed_algs = array())
120
120
// Check that this token has been created before 'now'. This prevents
121
121
// using tokens that have been created for later use (and haven't
122
122
// correctly used the nbf claim).
123
- if (isset ($ payload ->iat ) && $ payload ->iat > ($ timestamp + self ::$ leeway )) {
123
+ if (isset ($ payload ->iat ) && $ payload ->iat > ($ timestamp + static ::$ leeway )) {
124
124
throw new BeforeValidException (
125
125
'Cannot handle token prior to ' . date (DateTime::ISO8601 , $ payload ->iat )
126
126
);
127
127
}
128
128
129
129
// Check if this token has expired.
130
- if (isset ($ payload ->exp ) && ($ timestamp - self ::$ leeway ) >= $ payload ->exp ) {
130
+ if (isset ($ payload ->exp ) && ($ timestamp - static ::$ leeway ) >= $ payload ->exp ) {
131
131
throw new ExpiredException ('Expired token ' );
132
132
}
133
133
@@ -160,12 +160,12 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
160
160
$ header = array_merge ($ head , $ header );
161
161
}
162
162
$ segments = array ();
163
- $ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ header ));
164
- $ segments [] = JWT ::urlsafeB64Encode (JWT ::jsonEncode ($ payload ));
163
+ $ segments [] = static ::urlsafeB64Encode (static ::jsonEncode ($ header ));
164
+ $ segments [] = static ::urlsafeB64Encode (static ::jsonEncode ($ payload ));
165
165
$ signing_input = implode ('. ' , $ segments );
166
166
167
- $ signature = JWT ::sign ($ signing_input , $ key , $ alg );
168
- $ segments [] = JWT ::urlsafeB64Encode ($ signature );
167
+ $ signature = static ::sign ($ signing_input , $ key , $ alg );
168
+ $ segments [] = static ::urlsafeB64Encode ($ signature );
169
169
170
170
return implode ('. ' , $ segments );
171
171
}
@@ -184,10 +184,10 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
184
184
*/
185
185
public static function sign ($ msg , $ key , $ alg = 'HS256 ' )
186
186
{
187
- if (empty (self ::$ supported_algs [$ alg ])) {
187
+ if (empty (static ::$ supported_algs [$ alg ])) {
188
188
throw new DomainException ('Algorithm not supported ' );
189
189
}
190
- list ($ function , $ algorithm ) = self ::$ supported_algs [$ alg ];
190
+ list ($ function , $ algorithm ) = static ::$ supported_algs [$ alg ];
191
191
switch ($ function ) {
192
192
case 'hash_hmac ' :
193
193
return hash_hmac ($ algorithm , $ msg , $ key , true );
@@ -217,11 +217,11 @@ public static function sign($msg, $key, $alg = 'HS256')
217
217
*/
218
218
private static function verify ($ msg , $ signature , $ key , $ alg )
219
219
{
220
- if (empty (self ::$ supported_algs [$ alg ])) {
220
+ if (empty (static ::$ supported_algs [$ alg ])) {
221
221
throw new DomainException ('Algorithm not supported ' );
222
222
}
223
223
224
- list ($ function , $ algorithm ) = self ::$ supported_algs [$ alg ];
224
+ list ($ function , $ algorithm ) = static ::$ supported_algs [$ alg ];
225
225
switch ($ function ) {
226
226
case 'openssl ' :
227
227
$ success = openssl_verify ($ msg , $ signature , $ key , $ algorithm );
@@ -236,13 +236,13 @@ private static function verify($msg, $signature, $key, $alg)
236
236
if (function_exists ('hash_equals ' )) {
237
237
return hash_equals ($ signature , $ hash );
238
238
}
239
- $ len = min (self ::safeStrlen ($ signature ), self ::safeStrlen ($ hash ));
239
+ $ len = min (static ::safeStrlen ($ signature ), static ::safeStrlen ($ hash ));
240
240
241
241
$ status = 0 ;
242
242
for ($ i = 0 ; $ i < $ len ; $ i ++) {
243
243
$ status |= (ord ($ signature [$ i ]) ^ ord ($ hash [$ i ]));
244
244
}
245
- $ status |= (self ::safeStrlen ($ signature ) ^ self ::safeStrlen ($ hash ));
245
+ $ status |= (static ::safeStrlen ($ signature ) ^ static ::safeStrlen ($ hash ));
246
246
247
247
return ($ status === 0 );
248
248
}
@@ -276,7 +276,7 @@ public static function jsonDecode($input)
276
276
}
277
277
278
278
if (function_exists ('json_last_error ' ) && $ errno = json_last_error ()) {
279
- JWT ::handleJsonError ($ errno );
279
+ static ::handleJsonError ($ errno );
280
280
} elseif ($ obj === null && $ input !== 'null ' ) {
281
281
throw new DomainException ('Null result with non-null input ' );
282
282
}
@@ -296,7 +296,7 @@ public static function jsonEncode($input)
296
296
{
297
297
$ json = json_encode ($ input );
298
298
if (function_exists ('json_last_error ' ) && $ errno = json_last_error ()) {
299
- JWT ::handleJsonError ($ errno );
299
+ static ::handleJsonError ($ errno );
300
300
} elseif ($ json === 'null ' && $ input !== null ) {
301
301
throw new DomainException ('Null result with non-null input ' );
302
302
}
0 commit comments