From 9c55a7b61d2a97a4df8eb09f3e5295570ff31508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 4 Nov 2022 20:53:19 +0100 Subject: [PATCH] Deprecated method that uses static construction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To promote a symmetry on the usage of all algorithms, we're dropping the named constructor in favour of the normal constructor. Signed-off-by: Luís Cobucci --- docs/configuration.md | 4 -- docs/upgrading.md | 40 +++++++++++++++++++ infection.json.dist | 4 +- src/Signer/Ecdsa.php | 7 ++-- test/functional/ES512TokenTest.php | 4 +- test/functional/EcdsaTokenTest.php | 6 +-- .../MaliciousTamperingPreventionTest.php | 2 +- test/functional/RFC6978VectorTest.php | 6 +-- test/performance/Ecdsa/Sha256Bench.php | 2 +- test/performance/Ecdsa/Sha384Bench.php | 2 +- test/performance/Ecdsa/Sha512Bench.php | 2 +- test/unit/Signer/Ecdsa/Sha256Test.php | 2 +- test/unit/Signer/Ecdsa/Sha384Test.php | 2 +- test/unit/Signer/Ecdsa/Sha512Test.php | 2 +- 14 files changed, 61 insertions(+), 24 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 387ffde3..d2750837 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -105,10 +105,6 @@ $configuration = Configuration::forAsymmetricSigner( ); ``` -!!! Important - The implementation of ECDSA algorithms have a constructor dependency. - Use the `create()` named constructor to avoid having to handle it (e.g.: `Lcobucci\JWT\Signer\Ecdsa\Sha256::create()`). - ### For no algorithm !!! Warning diff --git a/docs/upgrading.md b/docs/upgrading.md index a15bf4d3..94591f45 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -2,6 +2,46 @@ Here we'll keep a list of all steps you need to take to make sure your code is compatible with newer versions. +## v4.x to v5.x + +The release `v5.0.0` is a modernised version of the library, which requires PHP 8.1+ and drops all the deprecated components. + +We're adding a few deprecation annotations on the version `v4.3.0`. +So, before going to `v5.0.0` please update to the latest 4.3.x version using composer: + +```sh +composer require lcobucci/jwt ^4.3 +``` + +Then run your tests and change all calls to deprecated methods, even if they are not triggering any notices. +Tools like [`phpstan/phpstan-deprecation-rules`](https://github.com/phpstan/phpstan-deprecation-rules) can help finding them. + +### Removal of `Ecdsa::create()` + +To promote symmetry on the instantiation of all algorithms (signers), we're dropping the named constructor in favour of the constructor. + +If you are using any variant of ECDSA, please change your code following this example: + +```diff + converter = $converter; + $this->converter = $converter ?? new MultibyteStringConverter(); } + /** @deprecated */ public static function create(): Ecdsa { - return new static(new MultibyteStringConverter()); // @phpstan-ignore-line + return new static(); // @phpstan-ignore-line } final public function sign(string $payload, Key $key): string diff --git a/test/functional/ES512TokenTest.php b/test/functional/ES512TokenTest.php index 34206ed1..a2889e77 100644 --- a/test/functional/ES512TokenTest.php +++ b/test/functional/ES512TokenTest.php @@ -51,7 +51,7 @@ class ES512TokenTest extends TestCase public function createConfiguration(): void { $this->config = Configuration::forAsymmetricSigner( - Sha512::create(), + new Sha512(), static::$ecdsaKeys['private_ec512'], static::$ecdsaKeys['public_ec512'] ); @@ -156,7 +156,7 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->config->validator()->assert( $token, new SignedWith( - Sha256::create(), + new Sha256(), self::$ecdsaKeys['public_ec512'] ) ); diff --git a/test/functional/EcdsaTokenTest.php b/test/functional/EcdsaTokenTest.php index 6e0a8252..4d6efaf5 100644 --- a/test/functional/EcdsaTokenTest.php +++ b/test/functional/EcdsaTokenTest.php @@ -53,7 +53,7 @@ class EcdsaTokenTest extends TestCase public function createConfiguration(): void { $this->config = Configuration::forAsymmetricSigner( - Sha256::create(), + new Sha256(), static::$ecdsaKeys['private'], static::$ecdsaKeys['public1'] ); @@ -158,7 +158,7 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->config->validator()->assert( $token, new SignedWith( - Sha512::create(), + new Sha512(), self::$ecdsaKeys['public1'] ) ); @@ -231,7 +231,7 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void $token = $this->config->parser()->parse($data); assert($token instanceof Token\Plain); - $constraint = new SignedWith(Sha512::create(), InMemory::plainText($key)); + $constraint = new SignedWith(new Sha512(), InMemory::plainText($key)); self::assertTrue($this->config->validator()->validate($token, $constraint)); self::assertEquals('world', $token->claims()->get('hello')); diff --git a/test/functional/MaliciousTamperingPreventionTest.php b/test/functional/MaliciousTamperingPreventionTest.php index 2f6cf369..f6d49f41 100644 --- a/test/functional/MaliciousTamperingPreventionTest.php +++ b/test/functional/MaliciousTamperingPreventionTest.php @@ -30,7 +30,7 @@ final class MaliciousTamperingPreventionTest extends TestCase public function createConfiguration(): void { $this->config = Configuration::forAsymmetricSigner( - ES512::create(), + new ES512(), InMemory::plainText('my-private-key'), InMemory::plainText( '-----BEGIN PUBLIC KEY-----' . PHP_EOL diff --git a/test/functional/RFC6978VectorTest.php b/test/functional/RFC6978VectorTest.php index d96d85b9..fc1fce99 100644 --- a/test/functional/RFC6978VectorTest.php +++ b/test/functional/RFC6978VectorTest.php @@ -59,7 +59,7 @@ public function dataRFC6979(): iterable /** @return mixed[] */ public function sha256Data(): iterable { - $signer = Sha256::create(); + $signer = new Sha256(); $key = InMemory::plainText( '-----BEGIN PUBLIC KEY-----' . PHP_EOL . 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYP7UuiVanTHJYet0xjVtaMBJuJI7' . PHP_EOL @@ -87,7 +87,7 @@ public function sha256Data(): iterable /** @return mixed[] */ public function sha384Data(): iterable { - $signer = Sha384::create(); + $signer = new Sha384(); $key = InMemory::plainText( '-----BEGIN PUBLIC KEY-----' . PHP_EOL . 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE7DpOQVtOGaRWhhgCn0J/pdqai8SukuAu' . PHP_EOL @@ -116,7 +116,7 @@ public function sha384Data(): iterable /** @return mixed[] */ public function sha512Data(): iterable { - $signer = Sha512::create(); + $signer = new Sha512(); $key = InMemory::plainText( '-----BEGIN PUBLIC KEY-----' . PHP_EOL . 'MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBiUVQ0HhZMuAOqiO2lPIT+MMSH4bc' . PHP_EOL diff --git a/test/performance/Ecdsa/Sha256Bench.php b/test/performance/Ecdsa/Sha256Bench.php index 877f3b18..eb559e8b 100644 --- a/test/performance/Ecdsa/Sha256Bench.php +++ b/test/performance/Ecdsa/Sha256Bench.php @@ -14,7 +14,7 @@ final class Sha256Bench extends SignerBench { protected function signer(): Signer { - return Sha256::create(); + return new Sha256(); } protected function signingKey(): Key diff --git a/test/performance/Ecdsa/Sha384Bench.php b/test/performance/Ecdsa/Sha384Bench.php index 167848c6..1ec6a0fc 100644 --- a/test/performance/Ecdsa/Sha384Bench.php +++ b/test/performance/Ecdsa/Sha384Bench.php @@ -14,7 +14,7 @@ final class Sha384Bench extends SignerBench { protected function signer(): Signer { - return Sha384::create(); + return new Sha384(); } protected function signingKey(): Key diff --git a/test/performance/Ecdsa/Sha512Bench.php b/test/performance/Ecdsa/Sha512Bench.php index 561c70b5..2f785b31 100644 --- a/test/performance/Ecdsa/Sha512Bench.php +++ b/test/performance/Ecdsa/Sha512Bench.php @@ -14,7 +14,7 @@ final class Sha512Bench extends SignerBench { protected function signer(): Signer { - return Sha512::create(); + return new Sha512(); } protected function signingKey(): Key diff --git a/test/unit/Signer/Ecdsa/Sha256Test.php b/test/unit/Signer/Ecdsa/Sha256Test.php index d8e33425..f3d542ce 100644 --- a/test/unit/Signer/Ecdsa/Sha256Test.php +++ b/test/unit/Signer/Ecdsa/Sha256Test.php @@ -20,7 +20,7 @@ final class Sha256Test extends TestCase */ public function createShouldReturnAValidInstance(): void { - $signer = Sha256::create(); + $signer = Sha256::create(); // @phpstan-ignore-line self::assertInstanceOf(Sha256::class, $signer); } diff --git a/test/unit/Signer/Ecdsa/Sha384Test.php b/test/unit/Signer/Ecdsa/Sha384Test.php index f2e355f6..294b42a2 100644 --- a/test/unit/Signer/Ecdsa/Sha384Test.php +++ b/test/unit/Signer/Ecdsa/Sha384Test.php @@ -20,7 +20,7 @@ final class Sha384Test extends TestCase */ public function createShouldReturnAValidInstance(): void { - $signer = Sha384::create(); + $signer = Sha384::create(); // @phpstan-ignore-line self::assertInstanceOf(Sha384::class, $signer); } diff --git a/test/unit/Signer/Ecdsa/Sha512Test.php b/test/unit/Signer/Ecdsa/Sha512Test.php index 484bc5fe..ed876531 100644 --- a/test/unit/Signer/Ecdsa/Sha512Test.php +++ b/test/unit/Signer/Ecdsa/Sha512Test.php @@ -20,7 +20,7 @@ final class Sha512Test extends TestCase */ public function createShouldReturnAValidInstance(): void { - $signer = Sha512::create(); + $signer = Sha512::create(); // @phpstan-ignore-line self::assertInstanceOf(Sha512::class, $signer); }