-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update libs and run linters * Update infection to v0.27 * Remove infection exceptions * Update phpUnit to v10 * Fix constructors * Add JwtSecretFactory * Add JwtSignerFactory::createRsa * Add JwtSignerFactory::createHmac
- Loading branch information
Showing
44 changed files
with
312 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "composer" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" | ||
allow: | ||
- dependency-name: "marvin255/optional" | ||
- dependency-name: "phpunit/phpunit" | ||
- dependency-name: "friendsofphp/php-cs-fixer" | ||
- dependency-name: "vimeo/psalm" | ||
- dependency-name: "infection/infection" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
colors="true" | ||
bootstrap="./vendor/autoload.php" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</coverage> | ||
|
||
<testsuites> | ||
<testsuite name="JWT tests suit"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"> | ||
<coverage/> | ||
<testsuites> | ||
<testsuite name="JWT tests suit"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Marvin255\Jwt\Exception; | ||
|
||
class SignerAlgorithmNotFoundException extends JwtException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Marvin255\Jwt; | ||
|
||
use Marvin255\Jwt\Signer\Secret; | ||
use Marvin255\Jwt\Signer\SecretBase; | ||
|
||
/** | ||
* Factory object for Secrets. | ||
*/ | ||
final class JwtSecretFactory | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Creates object that contains key secret. | ||
*/ | ||
public static function create(string $secret, string $passPhrase = null): Secret | ||
{ | ||
return new SecretBase($secret, $passPhrase); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Marvin255\Jwt; | ||
|
||
use Marvin255\Jwt\Exception\SignerAlgorithmNotFoundException; | ||
use Marvin255\Jwt\Signer\Algorithm; | ||
use Marvin255\Jwt\Signer\Hmac; | ||
use Marvin255\Jwt\Signer\NoneSigner; | ||
use Marvin255\Jwt\Signer\Rsa; | ||
use Marvin255\Jwt\Signer\Secret; | ||
|
||
/** | ||
* Factory object that can create signer objects. | ||
*/ | ||
final class JwtSignerFactory | ||
{ | ||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Creates RSA signer. | ||
*/ | ||
public static function createRsa(Algorithm $algorithm, Secret $public = null, Secret $private = null): JwtSigner | ||
{ | ||
$implementation = $algorithm->getImplementation(); | ||
if (!is_subclass_of($implementation, Rsa::class)) { | ||
throw new SignerAlgorithmNotFoundException('Wrong algorithm provided'); | ||
} | ||
|
||
return new $implementation($public, $private); | ||
} | ||
|
||
/** | ||
* Creates HMAC signer. | ||
*/ | ||
public static function createHmac(Algorithm $algorithm, Secret $secret): JwtSigner | ||
{ | ||
$implementation = $algorithm->getImplementation(); | ||
if (!is_subclass_of($implementation, Hmac::class)) { | ||
throw new SignerAlgorithmNotFoundException('Wrong algorithm provided'); | ||
} | ||
|
||
return new $implementation($secret); | ||
} | ||
|
||
/** | ||
* Creates empty signer that does nothing. | ||
*/ | ||
public static function createNone(): JwtSigner | ||
{ | ||
return new NoneSigner(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* Hmac sha 256 signer. | ||
* | ||
* @internal | ||
*/ | ||
final class HmacSha256Signer extends Hmac | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* Hmac sha 384 signer. | ||
* | ||
* @internal | ||
*/ | ||
final class HmacSha384Signer extends Hmac | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* Hmac sha 512 signer. | ||
* | ||
* @internal | ||
*/ | ||
final class HmacSha512Signer extends Hmac | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
/** | ||
* Signer for non signed tokens. | ||
* | ||
* @internal | ||
*/ | ||
final class NoneSigner implements JwtSigner | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* RSA sha 256 signer. | ||
* | ||
* @internal | ||
*/ | ||
final class RsaSha256Signer extends Rsa | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* RSA sha 384 signer. | ||
* | ||
* @internal | ||
*/ | ||
final class RsaSha384Signer extends Rsa | ||
{ | ||
|
Oops, something went wrong.