aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption')
-rw-r--r--vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/EncryptionInterface.php23
-rw-r--r--vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/Jwt.php58
2 files changed, 77 insertions, 4 deletions
diff --git a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/EncryptionInterface.php b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/EncryptionInterface.php
index 2d336c664..8dc720a43 100644
--- a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/EncryptionInterface.php
+++ b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/EncryptionInterface.php
@@ -4,8 +4,31 @@ namespace OAuth2\Encryption;
interface EncryptionInterface
{
+ /**
+ * @param $payload
+ * @param $key
+ * @param null $algorithm
+ * @return mixed
+ */
public function encode($payload, $key, $algorithm = null);
+
+ /**
+ * @param $payload
+ * @param $key
+ * @param null $algorithm
+ * @return mixed
+ */
public function decode($payload, $key, $algorithm = null);
+
+ /**
+ * @param $data
+ * @return mixed
+ */
public function urlSafeB64Encode($data);
+
+ /**
+ * @param $b64
+ * @return mixed
+ */
public function urlSafeB64Decode($b64);
}
diff --git a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/Jwt.php b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/Jwt.php
index ee576e643..c258b8fc3 100644
--- a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/Jwt.php
+++ b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Encryption/Jwt.php
@@ -2,12 +2,21 @@
namespace OAuth2\Encryption;
+use Exception;
+use InvalidArgumentException;
+
/**
* @link https://github.com/F21/jwt
* @author F21
*/
class Jwt implements EncryptionInterface
{
+ /**
+ * @param $payload
+ * @param $key
+ * @param string $algo
+ * @return string
+ */
public function encode($payload, $key, $algo = 'HS256')
{
$header = $this->generateJwtHeader($payload, $algo);
@@ -25,6 +34,12 @@ class Jwt implements EncryptionInterface
return implode('.', $segments);
}
+ /**
+ * @param string $jwt
+ * @param null $key
+ * @param array|bool $allowedAlgorithms
+ * @return bool|mixed
+ */
public function decode($jwt, $key = null, $allowedAlgorithms = true)
{
if (!strpos($jwt, '.')) {
@@ -67,6 +82,14 @@ class Jwt implements EncryptionInterface
return $payload;
}
+ /**
+ * @param $signature
+ * @param $input
+ * @param $key
+ * @param string $algo
+ * @return bool
+ * @throws InvalidArgumentException
+ */
private function verifySignature($signature, $input, $key, $algo = 'HS256')
{
// use constants when possible, for HipHop support
@@ -89,10 +112,17 @@ class Jwt implements EncryptionInterface
return @openssl_verify($input, $signature, $key, defined('OPENSSL_ALGO_SHA512') ? OPENSSL_ALGO_SHA512 : 'sha512') === 1;
default:
- throw new \InvalidArgumentException("Unsupported or invalid signing algorithm.");
+ throw new InvalidArgumentException("Unsupported or invalid signing algorithm.");
}
}
+ /**
+ * @param $input
+ * @param $key
+ * @param string $algo
+ * @return string
+ * @throws Exception
+ */
private function sign($input, $key, $algo = 'HS256')
{
switch ($algo) {
@@ -115,19 +145,30 @@ class Jwt implements EncryptionInterface
return $this->generateRSASignature($input, $key, defined('OPENSSL_ALGO_SHA512') ? OPENSSL_ALGO_SHA512 : 'sha512');
default:
- throw new \Exception("Unsupported or invalid signing algorithm.");
+ throw new Exception("Unsupported or invalid signing algorithm.");
}
}
+ /**
+ * @param $input
+ * @param $key
+ * @param string $algo
+ * @return mixed
+ * @throws Exception
+ */
private function generateRSASignature($input, $key, $algo)
{
if (!openssl_sign($input, $signature, $key, $algo)) {
- throw new \Exception("Unable to sign data.");
+ throw new Exception("Unable to sign data.");
}
return $signature;
}
+ /**
+ * @param string $data
+ * @return string
+ */
public function urlSafeB64Encode($data)
{
$b64 = base64_encode($data);
@@ -138,6 +179,10 @@ class Jwt implements EncryptionInterface
return $b64;
}
+ /**
+ * @param string $b64
+ * @return mixed|string
+ */
public function urlSafeB64Decode($b64)
{
$b64 = str_replace(array('-', '_'),
@@ -158,6 +203,11 @@ class Jwt implements EncryptionInterface
);
}
+ /**
+ * @param string $a
+ * @param string $b
+ * @return bool
+ */
protected function hash_equals($a, $b)
{
if (function_exists('hash_equals')) {
@@ -170,4 +220,4 @@ class Jwt implements EncryptionInterface
return $diff === 0;
}
-}
+} \ No newline at end of file