Passed
Push — master ( fbb13e...d759f2 )
by Milad
02:55
created

Algorithm::algorithm()   A

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 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