Passed
Push — master ( 106006...c1ddb5 )
by Thomas Mauro
06:38 queued 11s
created

jose_secret_key()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 3
nop 2
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient;
6
7
use Jose\Component\Core\JWK;
8
use function preg_match;
9
10
function jose_secret_key(string $secret, ?string $alg = null): JWK
11
{
12 46
    if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM)?KW$/', $alg, $matches)) {
13 6
        return derived_key($secret, (int) $matches[1]);
14
    }
15
16 40
    if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM|CBC-HS(\d{3}))$/', $alg, $matches)) {
17 6
        return derived_key($secret, (int) ($matches[2] ?? $matches[1]));
18
    }
19
20 34
    $key = new JWK([
21 34
        'k' => base64url_encode($secret),
22 34
        'kty' => 'oct',
23
    ]);
24
25 34
    return $key;
26
}
27