Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/functions/jose_secret_key.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient;
6
7 use Jose\Component\Core\JWK;
8
9 use function preg_match;
10
11 /**
12 * @internal
13 */
14 function jose_secret_key(string $secret, ?string $alg = null): JWK
15 {
16 if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM)?KW$/', $alg, $matches)) {
17 /** @psalm-var array{1: string} $matches */
18 return derived_key($secret, (int) $matches[1]);
19 }
20
21 if (null !== $alg && (bool) preg_match('/^A(\d{3})(?:GCM|CBC-HS(\d{3}))$/', $alg, $matches)) {
22 /** @psalm-var array{1: string, 2?: string} $matches */
23 return derived_key($secret, (int) ($matches[2] ?? $matches[1]));
24 }
25
26 $key = new JWK([
27 'k' => base64url_encode($secret),
28 'kty' => 'oct',
29 ]);
30
31 return $key;
32 }