Algorithm::algorithm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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