Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient;
6
7 use Jose\Component\Core\AlgorithmManager;
8 use Jose\Component\Encryption\Algorithm\ContentEncryption;
9 use Jose\Component\Encryption\Algorithm\KeyEncryption;
10 use Jose\Component\Signature\Algorithm;
11 use Throwable;
12
13 final class AlgorithmManagerBuilder
14 {
15 /**
16 * @var string[]
17 *
18 * @psalm-var list<class-string<\Jose\Component\Core\Algorithm>>
19 */
20 private array $algorithmClasses;
21
22 /**
23 * @param string[]|null $algorithmClasses
24 *
25 * @psalm-param null|list<class-string<\Jose\Component\Core\Algorithm>> $algorithmClasses
26 */
27 public function __construct(?array $algorithmClasses = null)
28 {
29 $this->algorithmClasses = $algorithmClasses ?? $this->getAlgorithms();
30 }
31
32 public function build(): AlgorithmManager
33 {
34 $algorithms = [];
35 foreach ($this->algorithmClasses as $algorithmClass) {
36 if (class_exists($algorithmClass)) {
37 try {
38 $algorithms[] = new $algorithmClass();
39 } catch (Throwable $throwable) {
40 // does nothing
41 }
42 }
43 }
44
45 return new AlgorithmManager($algorithms);
46 }
47
48 /**
49 * @return string[]
50 *
51 * @psalm-return list<class-string<\Jose\Component\Core\Algorithm>>
52 */
53 private function getAlgorithms(): array
54 {
55 return [
56 Algorithm\None::class,
57 Algorithm\HS256::class,
58 Algorithm\HS384::class,
59 Algorithm\HS512::class,
60 Algorithm\RS256::class,
61 Algorithm\RS384::class,
62 Algorithm\RS512::class,
63 Algorithm\PS256::class,
64 Algorithm\PS384::class,
65 Algorithm\PS512::class,
66 Algorithm\ES256::class,
67 Algorithm\ES384::class,
68 Algorithm\ES512::class,
69 Algorithm\EdDSA::class,
70 KeyEncryption\A128GCMKW::class,
71 KeyEncryption\A192GCMKW::class,
72 KeyEncryption\A256GCMKW::class,
73 KeyEncryption\A128KW::class,
74 KeyEncryption\A192KW::class,
75 KeyEncryption\A256KW::class,
76 KeyEncryption\Dir::class,
77 KeyEncryption\ECDHES::class,
78 KeyEncryption\ECDHESA128KW::class,
79 KeyEncryption\ECDHESA192KW::class,
80 KeyEncryption\ECDHESA256KW::class,
81 KeyEncryption\PBES2HS256A128KW::class,
82 KeyEncryption\PBES2HS384A192KW::class,
83 KeyEncryption\PBES2HS512A256KW::class,
84 KeyEncryption\RSA15::class,
85 KeyEncryption\RSAOAEP::class,
86 KeyEncryption\RSAOAEP256::class,
87 ContentEncryption\A128GCM::class,
88 ContentEncryption\A192GCM::class,
89 ContentEncryption\A256GCM::class,
90 ContentEncryption\A128CBCHS256::class,
91 ContentEncryption\A192CBCHS384::class,
92 ContentEncryption\A256CBCHS512::class,
93 ];
94 }
95 }