Skip to content

Commit c59b68d

Browse files
author
Chris Raynor
committed
whitespace cleanup
1 parent 3bb58d7 commit c59b68d

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

Authentication/JWT.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
1414
* @link https://github.com/firebase/php-jwt
1515
*/
16-
/**
17-
* JSON Web Token implementation, based on this spec:
18-
* http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
19-
*
20-
* @category Authentication
21-
* @package Authentication_JWT
22-
* @author Neuman Vong <[email protected]>
23-
* @author Anant Narayanan <[email protected]>
24-
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
25-
* @link https://github.com/firebase/php-jwt
26-
*/
2716
class JWT
2817
{
2918
static $methods = array(
@@ -32,13 +21,13 @@ class JWT
3221
'HS384' => array('hash_hmac', 'SHA384'),
3322
'RS256' => array('openssl', 'SHA256'),
3423
);
35-
24+
3625
/**
3726
* Decodes a JWT string into a PHP object.
3827
*
39-
* @param string $jwt The JWT
40-
* @param string|Array|null $key The secret key, or map of keys
41-
* @param bool $verify Don't skip verification process
28+
* @param string $jwt The JWT
29+
* @param string|Array|null $key The secret key, or map of keys
30+
* @param bool $verify Don't skip verification process
4231
*
4332
* @return object The JWT's payload as a PHP object
4433
* @throws UnexpectedValueException Provided JWT was invalid
@@ -71,7 +60,7 @@ public static function decode($jwt, $key = null, $verify = true)
7160
} else {
7261
throw new DomainException('"kid" empty, unable to lookup correct key');
7362
}
74-
}
63+
}
7564
if (!JWT::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) {
7665
throw new UnexpectedValueException('Signature verification failed');
7766
}
@@ -98,9 +87,9 @@ public static function decode($jwt, $key = null, $verify = true)
9887
public static function encode($payload, $key, $algo = 'HS256', $keyId = null)
9988
{
10089
$header = array('typ' => 'JWT', 'alg' => $algo);
101-
if($keyId !== null) {
102-
$header['kid'] = $keyId;
103-
}
90+
if($keyId !== null) {
91+
$header['kid'] = $keyId;
92+
}
10493
$segments = array();
10594
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
10695
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
@@ -115,10 +104,10 @@ public static function encode($payload, $key, $algo = 'HS256', $keyId = null)
115104
/**
116105
* Sign a string with a given key and algorithm.
117106
*
118-
* @param string $msg The message to sign
119-
* @param string|resource $key The secret key
120-
* @param string $method The signing algorithm. Supported
121-
* algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
107+
* @param string $msg The message to sign
108+
* @param string|resource $key The secret key
109+
* @param string $method The signing algorithm. Supported algorithms
110+
* are 'HS256', 'HS384', 'HS512' and 'RS256'
122111
*
123112
* @return string An encrypted message
124113
* @throws DomainException Unsupported algorithm was specified
@@ -142,7 +131,7 @@ public static function sign($msg, $key, $method = 'HS256')
142131
}
143132
}
144133
}
145-
134+
146135
/**
147136
* Verify a signature with the mesage, key and method. Not all methods
148137
* are symmetric, so we must have a separate verify and sign method.

tests/JWTTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,42 @@ function testMalformedJsonThrowsException() {
2929
JWT::jsonDecode('this is not valid JSON string');
3030
}
3131

32-
function testExpiredToken(){
32+
function testExpiredToken() {
3333
$this->setExpectedException('UnexpectedValueException');
3434
$payload = array(
35-
"message"=> "abc",
36-
"exp"=> time()-20); // time in the past
35+
"message" => "abc",
36+
"exp" => time() - 20); // time in the past
3737
$encoded = JWT::encode($payload, 'my_key');
3838
JWT::decode($encoded);
3939
}
4040

41-
function testValidToken(){
41+
function testValidToken() {
4242
$payload = array(
43-
"message"=> "abc",
44-
"exp"=> time()+20); // time in the future
43+
"message" => "abc",
44+
"exp" => time() + 20); // time in the future
4545
$encoded = JWT::encode($payload, 'my_key');
4646
$decoded = JWT::decode($encoded, 'my_key');
4747
$this->assertEquals($decoded->message, 'abc');
4848
}
4949

50-
function testRSEncodeDecode(){
50+
function testRSEncodeDecode() {
5151
$privKey = openssl_pkey_new(array('digest_alg' => 'sha256',
5252
'private_key_bits' => 1024,
5353
'private_key_type' => OPENSSL_KEYTYPE_RSA));
54-
$msg = JWT::encode('abc',$privKey, 'RS256');
54+
$msg = JWT::encode('abc', $privKey, 'RS256');
5555
$pubKey = openssl_pkey_get_details($privKey);
5656
$pubKey = $pubKey['key'];
5757
$decoded = JWT::decode($msg, $pubKey, true);
5858
$this->assertEquals($decoded, 'abc');
5959
}
6060

61-
function testKIDChooser(){
61+
function testKIDChooser() {
6262
$keys = array('1' => 'my_key', '2' => 'my_key2');
6363
$msg = JWT::encode('abc', $keys['1'], 'HS256', '1');
6464
$decoded = JWT::decode($msg, $keys, true);
6565
$this->assertEquals($decoded, 'abc');
6666
}
6767

68-
6968
}
7069

7170
?>

0 commit comments

Comments
 (0)