| Total Complexity | 6 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class RsaPublicKey |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var mixed Key resource handler |
||
| 13 | */ |
||
| 14 | protected $resource; |
||
| 15 | |||
| 16 | protected ?string $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $key Key file path or string content |
||
| 20 | * @param string|null $id Key identifier |
||
| 21 | * |
||
| 22 | * @throws InvalidKeyException |
||
| 23 | */ |
||
| 24 | public function __construct(string $key, ?string $id = null) |
||
| 25 | { |
||
| 26 | $content = realpath($key) ? file_get_contents(realpath($key)) : $key; |
||
| 27 | |||
| 28 | $this->resource = openssl_pkey_get_public($content); |
||
| 29 | if ($this->resource === false) { |
||
| 30 | throw new InvalidKeyException(openssl_error_string() ?: ''); |
||
| 31 | } |
||
| 32 | |||
| 33 | $this->id = $id; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | public function getResource() |
||
| 40 | { |
||
| 41 | return $this->resource; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getId(): ?string |
||
| 47 | } |
||
| 48 | } |
||
| 49 |