d01ec49214040accd12a3cc223be720d60a680eb
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Encryption\Algorithm\KeyEncryption;
6
7 use InvalidArgumentException;
8 use Jose\Component\Core\JWK;
9 use ParagonIE\ConstantTime\Base64UrlSafe;
10 use function in_array;
11 use function is_string;
12
13 final class Dir implements DirectEncryption
14 {
15 public function getCEK(JWK $key): string
16 {
17 if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) {
18 throw new InvalidArgumentException('Wrong key type.');
19 }
20 if (! $key->has('k')) {
21 throw new InvalidArgumentException('The key parameter "k" is missing.');
22 }
23 $k = $key->get('k');
24 if (! is_string($k)) {
25 throw new InvalidArgumentException('The key parameter "k" is invalid.');
26 }
27
28 return Base64UrlSafe::decodeNoPadding($k);
29 }
30
31 public function name(): string
32 {
33 return 'dir';
34 }
35
36 public function allowedKeyTypes(): array
37 {
38 return ['oct'];
39 }
40
41 public function getKeyManagementMode(): string
42 {
43 return self::MODE_DIRECT;
44 }
45 }