From d167ed191b376fb1a5094ec243f9e91a8f00b8f4 Mon Sep 17 00:00:00 2001 From: Zandor Smith Date: Fri, 9 Aug 2019 11:09:55 +0200 Subject: [PATCH 1/2] Support ES256. --- src/JWT.php | 1 + tests/JWTTest.php | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/JWT.php b/src/JWT.php index 22a67e32..14e4ba45 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -44,6 +44,7 @@ class JWT 'RS256' => array('openssl', 'SHA256'), 'RS384' => array('openssl', 'SHA384'), 'RS512' => array('openssl', 'SHA512'), + 'ES256' => array('openssl', 'SHA256'), ); /** diff --git a/tests/JWTTest.php b/tests/JWTTest.php index 804a3769..959034dd 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -206,17 +206,29 @@ public function testEmptyKeyFails() $decoded = JWT::decode($encoded, '', array('HS256')); } - public 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'); - $pubKey = openssl_pkey_get_details($privKey); - $pubKey = $pubKey['key']; - $decoded = JWT::decode($msg, $pubKey, array('RS256')); - $this->assertEquals($decoded, 'abc'); - } + public 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'); + $pubKey = openssl_pkey_get_details($privKey); + $pubKey = $pubKey['key']; + $decoded = JWT::decode($msg, $pubKey, array('RS256')); + $this->assertEquals($decoded, 'abc'); + } + + public function testESEncodeDecode() + { + $privKey = openssl_pkey_new(array('digest_alg' => 'sha256', + 'private_key_bits' => 1024, + 'private_key_type' => OPENSSL_KEYTYPE_RSA)); + $msg = JWT::encode('abc', $privKey, 'ES256'); + $pubKey = openssl_pkey_get_details($privKey); + $pubKey = $pubKey['key']; + $decoded = JWT::decode($msg, $pubKey, array('ES256')); + $this->assertEquals($decoded, 'abc'); + } public function testKIDChooser() { From 631b29741ef2fb663d411b29a00be09dec7e5814 Mon Sep 17 00:00:00 2001 From: Zandor Smith Date: Fri, 9 Aug 2019 11:13:25 +0200 Subject: [PATCH 2/2] Change indenting from tab to spaces. --- src/JWT.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JWT.php b/src/JWT.php index 14e4ba45..785dc683 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -44,7 +44,7 @@ class JWT 'RS256' => array('openssl', 'SHA256'), 'RS384' => array('openssl', 'SHA384'), 'RS512' => array('openssl', 'SHA512'), - 'ES256' => array('openssl', 'SHA256'), + 'ES256' => array('openssl', 'SHA256'), ); /**