3 declare(strict_types=1);
5 namespace Jose\Component\Encryption\Algorithm\KeyEncryption;
7 use InvalidArgumentException;
8 use Jose\Component\Core\JWK;
9 use ParagonIE\ConstantTime\Base64UrlSafe;
10 use function in_array;
11 use function is_string;
13 final class Dir implements DirectEncryption
15 public function getCEK(JWK $key): string
17 if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) {
18 throw new InvalidArgumentException('Wrong key type.');
20 if (! $key->has('k')) {
21 throw new InvalidArgumentException('The key parameter "k" is missing.');
24 if (! is_string($k)) {
25 throw new InvalidArgumentException('The key parameter "k" is invalid.');
28 return Base64UrlSafe::decodeNoPadding($k);
31 public function name(): string
36 public function allowedKeyTypes(): array
41 public function getKeyManagementMode(): string
43 return self::MODE_DIRECT;