Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
9 | class AbstractRsaSigner implements Signer |
||
10 | { |
||
11 | use Algorithm; |
||
12 | |||
13 | protected RsaPrivateKey $privateKey; |
||
14 | |||
15 | protected ?string $kid; |
||
16 | |||
17 | public function __construct(RsaPrivateKey $publicKey, ?string $kid = null) |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @inheritdoc |
||
25 | */ |
||
26 | public function sign(string $message): string |
||
27 | { |
||
28 | $signature = ''; |
||
29 | |||
30 | if (openssl_sign($message, $signature, $this->privateKey->getResource(), $this->algorithm()) === true) { |
||
31 | return $signature; |
||
32 | } |
||
33 | |||
34 | throw new SigningException(openssl_error_string() ?: "OpenSSL cannot sign the token."); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @inheritDoc |
||
39 | */ |
||
40 | public function kid(): ?string |
||
43 | } |
||
44 | |||
45 | public function getPrivateKey(): RsaPrivateKey |
||
48 | } |
||
49 | } |
||
50 |