Total Complexity | 6 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class AbstractRsaVerifier implements Verifier |
||
12 | { |
||
13 | use Algorithm; |
||
14 | |||
15 | protected RsaPublicKey $publicKey; |
||
16 | |||
17 | public function __construct(RsaPublicKey $publicKey) |
||
18 | { |
||
19 | $this->publicKey = $publicKey; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @inheritdoc |
||
24 | */ |
||
25 | public function verify(string $plain, string $signature): void |
||
26 | { |
||
27 | if (openssl_verify($plain, $signature, $this->publicKey->getResource(), $this->algorithm()) !== 1) { |
||
28 | throw new InvalidSignatureException(openssl_error_string() ?: "The signature is invalid."); |
||
29 | } |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @inheritDoc |
||
34 | */ |
||
35 | public function kid(): ?string |
||
38 | } |
||
39 | |||
40 | public function getPublicKey(): RsaPublicKey |
||
43 | } |
||
44 | } |
||
45 |