first commit
This commit is contained in:
49
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HMAC.php
vendored
Normal file
49
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HMAC.php
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jose\Component\Signature\Algorithm;
|
||||
|
||||
use function in_array;
|
||||
use InvalidArgumentException;
|
||||
use function is_string;
|
||||
use Jose\Component\Core\JWK;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
|
||||
abstract class HMAC implements MacAlgorithm
|
||||
{
|
||||
public function allowedKeyTypes(): array
|
||||
{
|
||||
return ['oct'];
|
||||
}
|
||||
|
||||
public function verify(JWK $key, string $input, string $signature): bool
|
||||
{
|
||||
return hash_equals($this->hash($key, $input), $signature);
|
||||
}
|
||||
|
||||
public function hash(JWK $key, string $input): string
|
||||
{
|
||||
$k = $this->getKey($key);
|
||||
|
||||
return hash_hmac($this->getHashAlgorithm(), $input, $k, true);
|
||||
}
|
||||
|
||||
protected function getKey(JWK $key): string
|
||||
{
|
||||
if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) {
|
||||
throw new InvalidArgumentException('Wrong key type.');
|
||||
}
|
||||
if (! $key->has('k')) {
|
||||
throw new InvalidArgumentException('The key parameter "k" is missing.');
|
||||
}
|
||||
$k = $key->get('k');
|
||||
if (! is_string($k)) {
|
||||
throw new InvalidArgumentException('The key parameter "k" is invalid.');
|
||||
}
|
||||
|
||||
return Base64UrlSafe::decode($k);
|
||||
}
|
||||
|
||||
abstract protected function getHashAlgorithm(): string;
|
||||
}
|
||||
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS256.php
vendored
Normal file
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS256.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jose\Component\Signature\Algorithm;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Jose\Component\Core\JWK;
|
||||
|
||||
final class HS256 extends HMAC
|
||||
{
|
||||
public function name(): string
|
||||
{
|
||||
return 'HS256';
|
||||
}
|
||||
|
||||
protected function getHashAlgorithm(): string
|
||||
{
|
||||
return 'sha256';
|
||||
}
|
||||
|
||||
protected function getKey(JWK $key): string
|
||||
{
|
||||
$k = parent::getKey($key);
|
||||
if (mb_strlen($k, '8bit') < 32) {
|
||||
throw new InvalidArgumentException('Invalid key length.');
|
||||
}
|
||||
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS384.php
vendored
Normal file
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS384.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jose\Component\Signature\Algorithm;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Jose\Component\Core\JWK;
|
||||
|
||||
final class HS384 extends HMAC
|
||||
{
|
||||
public function name(): string
|
||||
{
|
||||
return 'HS384';
|
||||
}
|
||||
|
||||
protected function getHashAlgorithm(): string
|
||||
{
|
||||
return 'sha384';
|
||||
}
|
||||
|
||||
protected function getKey(JWK $key): string
|
||||
{
|
||||
$k = parent::getKey($key);
|
||||
if (mb_strlen($k, '8bit') < 48) {
|
||||
throw new InvalidArgumentException('Invalid key length.');
|
||||
}
|
||||
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS512.php
vendored
Normal file
31
libraries/vendor/web-token/jwt-signature-algorithm-hmac/HS512.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jose\Component\Signature\Algorithm;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Jose\Component\Core\JWK;
|
||||
|
||||
final class HS512 extends HMAC
|
||||
{
|
||||
public function name(): string
|
||||
{
|
||||
return 'HS512';
|
||||
}
|
||||
|
||||
protected function getHashAlgorithm(): string
|
||||
{
|
||||
return 'sha512';
|
||||
}
|
||||
|
||||
protected function getKey(JWK $key): string
|
||||
{
|
||||
$k = parent::getKey($key);
|
||||
if (mb_strlen($k, '8bit') < 64) {
|
||||
throw new InvalidArgumentException('Invalid key length.');
|
||||
}
|
||||
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
21
libraries/vendor/web-token/jwt-signature-algorithm-hmac/LICENSE
vendored
Normal file
21
libraries/vendor/web-token/jwt-signature-algorithm-hmac/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2019 Spomky-Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Reference in New Issue
Block a user