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