diff --git a/src/Signer/Algorithm.php b/src/Signer/Algorithm.php index a69f55a..45035e0 100644 --- a/src/Signer/Algorithm.php +++ b/src/Signer/Algorithm.php @@ -29,4 +29,26 @@ public function getPhpAlgName(): string default => '', }; } + + public function getImplementation(): string + { + return match ($this) { + Algorithm::HMAC_SHA_256 => HmacSha256Signer::class, + Algorithm::HMAC_SHA_384 => HmacSha384Signer::class, + Algorithm::HMAC_SHA_512 => HmacSha512Signer::class, + Algorithm::RSA_SHA_256 => RsaSha256Signer::class, + Algorithm::RSA_SHA_384 => RsaSha384Signer::class, + Algorithm::RSA_SHA_512 => RsaSha512Signer::class, + Algorithm::NONE => NoneSigner::class, + }; + } + + public function getType(): AlgorithmType + { + return match ($this) { + Algorithm::HMAC_SHA_256, Algorithm::HMAC_SHA_384, Algorithm::HMAC_SHA_512 => AlgorithmType::HMAC, + Algorithm::RSA_SHA_256, Algorithm::RSA_SHA_384, Algorithm::RSA_SHA_512 => AlgorithmType::RSA, + Algorithm::NONE => AlgorithmType::NONE, + }; + } } diff --git a/src/Signer/AlgorithmType.php b/src/Signer/AlgorithmType.php new file mode 100644 index 0000000..dc3cc57 --- /dev/null +++ b/src/Signer/AlgorithmType.php @@ -0,0 +1,15 @@ +assertSame($result, $alg->getImplementation()); + } + + public function provideGetImplementation(): array + { + return [ + 'NONE' => [ + Algorithm::NONE, + NoneSigner::class, + ], + 'HMAC_SHA_256' => [ + Algorithm::HMAC_SHA_256, + HmacSha256Signer::class, + ], + 'HMAC_SHA_384' => [ + Algorithm::HMAC_SHA_384, + HmacSha384Signer::class, + ], + 'HMAC_SHA_512' => [ + Algorithm::HMAC_SHA_512, + HmacSha512Signer::class, + ], + 'RSA_SHA_256' => [ + Algorithm::RSA_SHA_256, + RsaSha256Signer::class, + ], + 'RSA_SHA_384' => [ + Algorithm::RSA_SHA_384, + RsaSha384Signer::class, + ], + 'RSA_SHA_512' => [ + Algorithm::RSA_SHA_512, + RsaSha512Signer::class, + ], + ]; + } + + /** + * @dataProvider provideTestGetType + */ + public function testGetType(Algorithm $alg, AlgorithmType $result): void + { + $this->assertSame($result, $alg->getType()); + } + + public function provideTestGetType(): array + { + return [ + 'NONE' => [ + Algorithm::NONE, + AlgorithmType::NONE, + ], + 'HMAC_SHA_256' => [ + Algorithm::HMAC_SHA_256, + AlgorithmType::HMAC, + ], + 'HMAC_SHA_384' => [ + Algorithm::HMAC_SHA_384, + AlgorithmType::HMAC, + ], + 'HMAC_SHA_512' => [ + Algorithm::HMAC_SHA_512, + AlgorithmType::HMAC, + ], + 'RSA_SHA_256' => [ + Algorithm::RSA_SHA_256, + AlgorithmType::RSA, + ], + 'RSA_SHA_384' => [ + Algorithm::RSA_SHA_384, + AlgorithmType::RSA, + ], + 'RSA_SHA_512' => [ + Algorithm::RSA_SHA_512, + AlgorithmType::RSA, + ], + ]; + } }