1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace MiladRahimi\Jwt\Cryptography\Algorithms\Ecdsa; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Automatic algorithm-based value generator |
7
|
|
|
*/ |
8
|
|
|
trait Algorithm |
9
|
|
|
{ |
10
|
|
|
protected static string $name; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @inheritdoc |
14
|
|
|
*/ |
15
|
|
|
public function name(): string |
16
|
|
|
{ |
17
|
|
|
return static::$name; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
protected function algorithm(): int |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
'ES256' => OPENSSL_ALGO_SHA256, |
24
|
|
|
'ES256K' => OPENSSL_ALGO_SHA256, |
25
|
|
|
'ES384' => OPENSSL_ALGO_SHA512, |
26
|
|
|
][$this->name()]; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function keySize(): int |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'ES256' => 256, |
33
|
|
|
'ES256K' => 256, |
34
|
|
|
'ES384' => 384, |
35
|
|
|
][static::$name]; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|