summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn LeSueur <jlesueur@bamboohr.com>2014-06-23 18:38:44 +0000
committerJohn LeSueur <jlesueur@bamboohr.com>2014-06-23 18:38:44 +0000
commit026a6d9c45bd0cc702703c06b615e3ec216c4802 (patch)
treeab2d855021b562294aee9ada22738a0142fe0676
parentb5829858aed4a1f73c3029ecaf3e34471a083e6e (diff)
downloadphp-jwt-026a6d9c45bd0cc702703c06b615e3ec216c4802.zip
php-jwt-026a6d9c45bd0cc702703c06b615e3ec216c4802.tar.gz
php-jwt-026a6d9c45bd0cc702703c06b615e3ec216c4802.tar.bz2
Updates for some whitespace and other minor issues.
-rw-r--r--Authentication/JWT.php12
-rw-r--r--tests/JWTTest.php6
2 files changed, 10 insertions, 8 deletions
diff --git a/Authentication/JWT.php b/Authentication/JWT.php
index aa4995d..d82e2cc 100644
--- a/Authentication/JWT.php
+++ b/Authentication/JWT.php
@@ -65,10 +65,12 @@ class JWT
if (empty($header->alg)) {
throw new DomainException('Empty algorithm');
}
- if (is_array($key) && !isset($header->kid)) {
- throw new DomainException('"kid" empty, unable to lookup correct key');
- } elseif(is_array($key) && isset($header->kid)) {
- $key = $key[$header->kid];
+ if (is_array($key)) {
+ if(isset($header->kid)) {
+ $key = $key[$header->kid];
+ } else {
+ throw new DomainException('"kid" empty, unable to lookup correct key');
+ }
}
if (!JWT::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
throw new UnexpectedValueException('Signature verification failed');
@@ -116,7 +118,7 @@ class JWT
* @param string $msg The message to sign
* @param string|resource $key The secret key
* @param string $method The signing algorithm. Supported
- * algorithms are 'HS256', 'HS384' and 'HS512'
+ * algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
*
* @return string An encrypted message
* @throws DomainException Unsupported algorithm was specified
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
index 5aa5dc7..bdd8514 100644
--- a/tests/JWTTest.php
+++ b/tests/JWTTest.php
@@ -47,8 +47,8 @@ class JWTTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($decoded->message, 'abc');
}
- function testRSEncodeDecode() {
- $privKey = openssl_pkey_new(array('digest_alg' => 'sha256',
+ function testRSEncodeDecode(){
+ $privKey = openssl_pkey_new(array('digest_alg' => 'sha256',
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA));
$msg = JWT::encode('abc',$privKey, 'RS256');
@@ -58,7 +58,7 @@ class JWTTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($decoded, 'abc');
}
- function testKIDChooser() {
+ function testKIDChooser(){
$keys = array('1' => 'my_key', '2' => 'my_key2');
$msg = JWT::encode('abc', $keys['1'], 'HS256', '1');
$decoded = JWT::decode($msg, $keys, true);