11<?php
22
3+ namespace Firebase \JWT ;
4+ use \DomainException ;
5+ use \UnexpectedValueException ;
6+ use \DateTime ;
7+
38/**
49 * JSON Web Token implementation, based on this spec:
510 * http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
@@ -33,11 +38,13 @@ class JWT
3338 /**
3439 * Decodes a JWT string into a PHP object.
3540 *
36- * @param string $jwt The JWT
37- * @param string|Array|null $key The secret key, or map of keys
38- * @param Array $allowed_algs List of supported verification algorithms
41+ * @param string $jwt The JWT
42+ * @param string|array|null $key The key, or map of keys.
43+ * If the algorithm used is asymmetric, this is the public key
44+ * @param array $allowed_algs List of supported verification algorithms
45+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
3946 *
40- * @return object The JWT's payload as a PHP object
47+ * @return object The JWT's payload as a PHP object
4148 *
4249 * @throws DomainException Algorithm was not provided
4350 * @throws UnexpectedValueException Provided JWT was invalid
@@ -117,13 +124,15 @@ public static function decode($jwt, $key, $allowed_algs = array())
117124 /**
118125 * Converts and signs a PHP object or array into a JWT string.
119126 *
120- * @param object|array $payload PHP object or array
121- * @param string $key The secret key
122- * @param string $alg The signing algorithm. Supported
123- * algorithms are 'HS256', 'HS384' and 'HS512'
124- * @param array $head An array with header elements to attach
127+ * @param object|array $payload PHP object or array
128+ * @param string $key The secret key.
129+ * If the algorithm used is asymmetric, this is the private key
130+ * @param string $alg The signing algorithm.
131+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
132+ * @param array $head An array with header elements to attach
133+ *
134+ * @return string A signed JWT
125135 *
126- * @return string A signed JWT
127136 * @uses jsonEncode
128137 * @uses urlsafeB64Encode
129138 */
@@ -150,12 +159,13 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
150159 /**
151160 * Sign a string with a given key and algorithm.
152161 *
153- * @param string $msg The message to sign
154- * @param string|resource $key The secret key
155- * @param string $alg The signing algorithm. Supported algorithms
156- * are 'HS256', 'HS384', 'HS512' and 'RS256'
162+ * @param string $msg The message to sign
163+ * @param string|resource $key The secret key
164+ * @param string $alg The signing algorithm.
165+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
166+ *
167+ * @return string An encrypted message
157168 *
158- * @return string An encrypted message
159169 * @throws DomainException Unsupported algorithm was specified
160170 */
161171 public static function sign ($ msg , $ key , $ alg = 'HS256 ' )
@@ -179,13 +189,16 @@ public static function sign($msg, $key, $alg = 'HS256')
179189 }
180190
181191 /**
182- * Verify a signature with the mesage , key and method. Not all methods
192+ * Verify a signature with the message , key and method. Not all methods
183193 * are symmetric, so we must have a separate verify and sign method.
184- * @param string $msg the original message
185- * @param string $signature
186- * @param string|resource $key for HS*, a string key works. for RS*, must be a resource of an openssl public key
187- * @param string $alg
194+ *
195+ * @param string $msg The original message (header and body)
196+ * @param string $signature The original signature
197+ * @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key
198+ * @param string $alg The algorithm
199+ *
188200 * @return bool
201+ *
189202 * @throws DomainException Invalid Algorithm or OpenSSL failure
190203 */
191204 private static function verify ($ msg , $ signature , $ key , $ alg )
@@ -226,7 +239,8 @@ private static function verify($msg, $signature, $key, $alg)
226239 *
227240 * @param string $input JSON string
228241 *
229- * @return object Object representation of JSON string
242+ * @return object Object representation of JSON string
243+ *
230244 * @throws DomainException Provided string was invalid JSON
231245 */
232246 public static function jsonDecode ($ input )
@@ -260,7 +274,8 @@ public static function jsonDecode($input)
260274 *
261275 * @param object|array $input A PHP object or array
262276 *
263- * @return string JSON representation of the PHP object or array
277+ * @return string JSON representation of the PHP object or array
278+ *
264279 * @throws DomainException Provided object could not be encoded to valid JSON
265280 */
266281 public static function jsonEncode ($ input )
@@ -328,6 +343,7 @@ private static function handleJsonError($errno)
328343 * Get the number of bytes in cryptographic strings.
329344 *
330345 * @param string
346+ *
331347 * @return int
332348 */
333349 private static function safeStrlen ($ str )
0 commit comments