<?php declare(strict_types=1); namespace Jose\Component\Encryption\Algorithm\KeyEncryption; use function in_array; use InvalidArgumentException; use function is_string; use Jose\Component\Core\JWK; use ParagonIE\ConstantTime\Base64UrlSafe; final class Dir implements DirectEncryption { public function getCEK(JWK $key): string { if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) { throw new InvalidArgumentException('Wrong key type.'); } if (! $key->has('k')) { throw new InvalidArgumentException('The key parameter "k" is missing.'); } $k = $key->get('k'); if (! is_string($k)) { throw new InvalidArgumentException('The key parameter "k" is invalid.'); } return Base64UrlSafe::decode($k); } public function name(): string { return 'dir'; } public function allowedKeyTypes(): array { return ['oct']; } public function getKeyManagementMode(): string { return self::MODE_DIRECT; } }