| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Jose\Component\Signature\Algorithm; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | use Jose\Component\Core\JWK; |
| 9 | use function in_array; |
| 10 | |
| 11 | final class None implements SignatureAlgorithm |
| 12 | { |
| 13 | public function allowedKeyTypes(): array |
| 14 | { |
| 15 | return ['none']; |
| 16 | } |
| 17 | |
| 18 | public function sign(JWK $key, string $input): string |
| 19 | { |
| 20 | $this->checkKey($key); |
| 21 | |
| 22 | return ''; |
| 23 | } |
| 24 | |
| 25 | public function verify(JWK $key, string $input, string $signature): bool |
| 26 | { |
| 27 | return $signature === ''; |
| 28 | } |
| 29 | |
| 30 | public function name(): string |
| 31 | { |
| 32 | return 'none'; |
| 33 | } |
| 34 | |
| 35 | private function checkKey(JWK $key): void |
| 36 | { |
| 37 | if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) { |
| 38 | throw new InvalidArgumentException('Wrong key type.'); |
| 39 | } |
| 40 | } |
| 41 | } |