22
33namespace  Firebase \JWT ;
44use  \DomainException ;
5+ use  \InvalidArgumentException ;
56use  \UnexpectedValueException ;
67use  \DateTime ;
78
@@ -56,8 +57,11 @@ class JWT
5657 * @uses jsonDecode 
5758 * @uses urlsafeB64Decode 
5859 */ 
59-  public  static  function  decode ($ jwt$ key =  null , $ allowed_algsarray ())
60+  public  static  function  decode ($ jwt$ key$ allowed_algsarray ())
6061 {
62+  if  (empty ($ key
63+  throw  new  InvalidArgumentException ('Key may not be empty ' );
64+  }
6165 $ tksexplode ('. ' , $ jwt
6266 if  (count ($ tks3 ) {
6367 throw  new  UnexpectedValueException ('Wrong number of segments ' );
@@ -70,50 +74,49 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
7074 throw  new  UnexpectedValueException ('Invalid claims encoding ' );
7175 }
7276 $ sigJWT ::urlsafeB64Decode ($ cryptob64
73-  if  (isset ($ key
74-  if  (empty ($ headeralg )) {
75-  throw  new  DomainException ('Empty algorithm ' );
76-  }
77-  if  (empty (self ::$ supported_algs$ headeralg ])) {
78-  throw  new  DomainException ('Algorithm not supported ' );
79-  }
80-  if  (!is_array ($ allowed_algsin_array ($ headeralg , $ allowed_algs
81-  throw  new  DomainException ('Algorithm not allowed ' );
82-  }
83-  if  (is_array ($ key$ keyinstanceof  \ArrayAccess) {
84-  if  (isset ($ headerkid )) {
85-  $ key$ key$ headerkid ];
86-  } else  {
87-  throw  new  DomainException ('"kid" empty, unable to lookup correct key ' );
88-  }
77+  
78+  if  (empty ($ headeralg )) {
79+  throw  new  DomainException ('Empty algorithm ' );
80+  }
81+  if  (empty (self ::$ supported_algs$ headeralg ])) {
82+  throw  new  DomainException ('Algorithm not supported ' );
83+  }
84+  if  (!is_array ($ allowed_algsin_array ($ headeralg , $ allowed_algs
85+  throw  new  DomainException ('Algorithm not allowed ' );
86+  }
87+  if  (is_array ($ key$ keyinstanceof  \ArrayAccess) {
88+  if  (isset ($ headerkid )) {
89+  $ key$ key$ headerkid ];
90+  } else  {
91+  throw  new  DomainException ('"kid" empty, unable to lookup correct key ' );
8992 }
93+  }
9094
91-    // Check the signature 
92-    if  (!JWT ::verify ("$ headb64. $ bodyb64 , $ sig$ key$ headeralg )) {
93-    throw  new  SignatureInvalidException ('Signature verification failed ' );
94-    }
95+  // Check the signature 
96+  if  (!JWT ::verify ("$ headb64. $ bodyb64 , $ sig$ key$ headeralg )) {
97+  throw  new  SignatureInvalidException ('Signature verification failed ' );
98+  }
9599
96-    // Check if the nbf if it is defined. This is the time that the 
97-    // token can actually be used. If it's not yet that time, abort. 
98-    if  (isset ($ payloadnbf ) && $ payloadnbf  > (time () + self ::$ leeway
99-    throw  new  BeforeValidException (
100-    'Cannot handle token prior to  '  . date (DateTime::ISO8601 , $ payloadnbf )
101-    );
102-    }
100+  // Check if the nbf if it is defined. This is the time that the 
101+  // token can actually be used. If it's not yet that time, abort. 
102+  if  (isset ($ payloadnbf ) && $ payloadnbf  > (time () + self ::$ leeway
103+  throw  new  BeforeValidException (
104+  'Cannot handle token prior to  '  . date (DateTime::ISO8601 , $ payloadnbf )
105+  );
106+  }
103107
104-    // Check that this token has been created before 'now'. This prevents 
105-    // using tokens that have been created for later use (and haven't 
106-    // correctly used the nbf claim). 
107-    if  (isset ($ payloadiat ) && $ payloadiat  > (time () + self ::$ leeway
108-    throw  new  BeforeValidException (
109-    'Cannot handle token prior to  '  . date (DateTime::ISO8601 , $ payloadiat )
110-    );
111-    }
108+  // Check that this token has been created before 'now'. This prevents 
109+  // using tokens that have been created for later use (and haven't 
110+  // correctly used the nbf claim). 
111+  if  (isset ($ payloadiat ) && $ payloadiat  > (time () + self ::$ leeway
112+  throw  new  BeforeValidException (
113+  'Cannot handle token prior to  '  . date (DateTime::ISO8601 , $ payloadiat )
114+  );
115+  }
112116
113-  // Check if this token has expired. 
114-  if  (isset ($ payloadexp ) && (time () - self ::$ leeway$ payloadexp ) {
115-  throw  new  ExpiredException ('Expired token ' );
116-  }
117+  // Check if this token has expired. 
118+  if  (isset ($ payloadexp ) && (time () - self ::$ leeway$ payloadexp ) {
119+  throw  new  ExpiredException ('Expired token ' );
117120 }
118121
119122 return  $ payload
0 commit comments