Debian Codegraph @

lib/3rdParty/composer/facile-it/php-jose-verifier/src/Internal/functions/jose_secret_key.php

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