CoreFiles by mySites.guru
Dir.php45 lines, 1,086 bytes, from Joomla_5.2.0-alpha3-Alpha-Full_Package.zip
Raw History Compare with 5.2.0-alpha2
md5
10192075832d6721cc16b1b019f6b7cd
sha1
1f35f8e47c125c4a2d9c102b6416a5b7d34e0bc6
sha256
3ddd1364442ca5bb05b22aeba122d59c1a040bf6955c8b647725e4bc6faf2258
<?php

declare(strict_types=1);

namespace Jose\Component\Encryption\Algorithm\KeyEncryption;

use InvalidArgumentException;
use Jose\Component\Core\JWK;
use ParagonIE\ConstantTime\Base64UrlSafe;
use function in_array;
use function is_string;

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::decodeNoPadding($k);
    }

    public function name(): string
    {
        return 'dir';
    }

    public function allowedKeyTypes(): array
    {
        return ['oct'];
    }

    public function getKeyManagementMode(): string
    {
        return self::MODE_DIRECT;
    }
}

The same content is in 19 releases, Joomla 5.1.0-beta1 to 5.2.0-alpha3. See them all, or every version of this file.