Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligned the DocBlocks #62

Merged
merged 1 commit into from
Jul 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class JWT
/**
* Decodes a JWT string into a PHP object.
*
* @param string $jwt The JWT
* @param string|Array|null $key The secret key, or map of keys
* @param Array $allowed_algs List of supported verification algorithms
* @param string $jwt The JWT
* @param string|array|null $key The key, or map of keys.
* If the algorithm used is asymmetric, this is the public key
* @param array $allowed_algs List of supported verification algorithms
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @return object The JWT's payload as a PHP object
* @return object The JWT's payload as a PHP object
*
* @throws DomainException Algorithm was not provided
* @throws UnexpectedValueException Provided JWT was invalid
Expand Down Expand Up @@ -120,13 +122,15 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
/**
* Converts and signs a PHP object or array into a JWT string.
*
* @param object|array $payload PHP object or array
* @param string $key The secret key
* @param string $alg The signing algorithm. Supported
* algorithms are 'HS256', 'HS384' and 'HS512'
* @param array $head An array with header elements to attach
* @param object|array $payload PHP object or array
* @param string $key The secret key.
* If the algorithm used is asymmetric, this is the private key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
* @param array $head An array with header elements to attach
*
* @return string A signed JWT
*
* @return string A signed JWT
* @uses jsonEncode
* @uses urlsafeB64Encode
*/
Expand All @@ -153,12 +157,13 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
/**
* Sign a string with a given key and algorithm.
*
* @param string $msg The message to sign
* @param string|resource $key The secret key
* @param string $alg The signing algorithm. Supported algorithms
* are 'HS256', 'HS384', 'HS512' and 'RS256'
* @param string $msg The message to sign
* @param string|resource $key The secret key
* @param string $alg The signing algorithm.
* Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @return string An encrypted message
*
* @return string An encrypted message
* @throws DomainException Unsupported algorithm was specified
*/
public static function sign($msg, $key, $alg = 'HS256')
Expand All @@ -182,13 +187,16 @@ public static function sign($msg, $key, $alg = 'HS256')
}

/**
* Verify a signature with the mesage, key and method. Not all methods
* Verify a signature with the message, key and method. Not all methods
* are symmetric, so we must have a separate verify and sign method.
* @param string $msg the original message
* @param string $signature
* @param string|resource $key for HS*, a string key works. for RS*, must be a resource of an openssl public key
* @param string $alg
*
* @param string $msg The original message (header and body)
* @param string $signature The original signature
* @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key
* @param string $alg The algorithm
*
* @return bool
*
* @throws DomainException Invalid Algorithm or OpenSSL failure
*/
private static function verify($msg, $signature, $key, $alg)
Expand Down Expand Up @@ -229,7 +237,8 @@ private static function verify($msg, $signature, $key, $alg)
*
* @param string $input JSON string
*
* @return object Object representation of JSON string
* @return object Object representation of JSON string
*
* @throws DomainException Provided string was invalid JSON
*/
public static function jsonDecode($input)
Expand Down Expand Up @@ -263,7 +272,8 @@ public static function jsonDecode($input)
*
* @param object|array $input A PHP object or array
*
* @return string JSON representation of the PHP object or array
* @return string JSON representation of the PHP object or array
*
* @throws DomainException Provided object could not be encoded to valid JSON
*/
public static function jsonEncode($input)
Expand Down Expand Up @@ -331,6 +341,7 @@ private static function handleJsonError($errno)
* Get the number of bytes in cryptographic strings.
*
* @param string
*
* @return int
*/
private static function safeStrlen($str)
Expand Down