Total Complexity | 7 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
11 | class EdDsaSigner implements Signer |
||
12 | { |
||
13 | protected static string $name = 'EdDSA'; |
||
14 | |||
15 | protected string $privateKey; |
||
16 | |||
17 | protected ?string $kid; |
||
18 | |||
19 | public function __construct(string $privateKey, ?string $kid = null) |
||
20 | { |
||
21 | $this->privateKey = $privateKey; |
||
22 | $this->kid = $kid; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | public function sign(string $message): string |
||
29 | { |
||
30 | if (function_exists('sodium_crypto_sign_detached')) { |
||
31 | try { |
||
32 | return sodium_crypto_sign_detached($message, $this->privateKey); |
||
33 | } catch (SodiumException $e) { |
||
34 | throw new SigningException("Cannot sign using Sodium extension", 0, $e); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | throw new RuntimeException('The sodium_crypto_sign_detached function is not available'); |
||
39 | } |
||
40 | |||
41 | public function name(): string |
||
44 | } |
||
45 | |||
46 | public function kid(): ?string |
||
47 | { |
||
48 | return $this->kid; |
||
49 | } |
||
50 | |||
51 | public function getPrivateKey(): string |
||
54 | } |
||
55 | } |
||
56 |