Passed
Push — master ( f80f70...56399a )
by Thomas Mauro
03:05 queued 10s
created

derived_key.php ➔ derived_key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient;
6
7
use function hash;
8
use Jose\Component\Core\JWK;
9
use function substr;
10
11
function derived_key(string $secret, int $length): JWK
12
{
13 16
    $hash = substr(hash('sha256', $secret, true), 0, (int) round($length / 8));
14
15 16
    return new JWK([
16 16
        'k' => base64url_encode($hash),
17 16
        'kty' => 'oct',
18
    ]);
19
}
20