Passed
Push — master ( 898cc7...450add )
by Thomas Mauro
03:07
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 6
CRAP Score 5.3906

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 3
nop 2
dl 0
loc 16
ccs 6
cts 8
cp 0.75
crap 5.3906
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
9
function jose_secret_key(string $secret, ?string $alg = null): JWK
10
{
11 1
    if ($alg && \preg_match('/^A(\d{3})(?:GCM)?KW$/', $alg, $matches)) {
12
        return derived_key($secret, (int) $matches[1]);
13
    }
14
15 1
    if ($alg && \preg_match('/^A(\d{3})(?:GCM|CBC-HS(\d{3}))$/', $alg, $matches)) {
16
        return derived_key($secret, (int) ($matches[2] ?? $matches[1]));
17
    }
18
19 1
    $key = new JWK([
20 1
        'k' => base64url_encode($secret),
21 1
        'kty' => 'oct',
22
    ]);
23
24 1
    return $key;
25
}
26