Passed
Push — master ( f46a06...f1e8df )
by Milad
02:47
created

EcdsaPublicKey::close()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace MiladRahimi\Jwt\Cryptography\Keys;
4
5
use MiladRahimi\Jwt\Exceptions\InvalidKeyException;
6
use Throwable;
7
8
class EcdsaPublicKey
9
{
10
    /**
11
     * @var mixed Key file resource handler
12
     */
13
    private $resource;
14
15
    /**
16
     * @throws InvalidKeyException
17
     */
18
    public function __construct(string $filePath)
19
    {
20
        try {
21
            $this->resource = openssl_pkey_get_public(file_get_contents(realpath($filePath)));
22
        } catch (Throwable $e) {
23
            throw new InvalidKeyException('Failed to read the key.', 0, $e);
24
        }
25
26
        if ($this->resource === false) {
27
            throw new InvalidKeyException(openssl_error_string());
28
        }
29
    }
30
31
    /**
32
     * @return mixed
33
     */
34
    public function getResource()
35
    {
36
        return $this->resource;
37
    }
38
}
39