| @@ 35-69 (lines=35) @@ | ||
| 32 | /** |
|
| 33 | * @package Limoncello\Crypt |
|
| 34 | */ |
|
| 35 | class AsymmetricPrivateEncryptPublicDecryptContainerConfigurator implements ContainerConfiguratorInterface |
|
| 36 | { |
|
| 37 | /** @var callable */ |
|
| 38 | const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME]; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @inheritdoc |
|
| 42 | */ |
|
| 43 | public static function configureContainer(LimoncelloContainerInterface $container): void |
|
| 44 | { |
|
| 45 | $container[EncryptInterface::class] = function (PsrContainerInterface $container): EncryptInterface { |
|
| 46 | $settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 47 | $keyOrPath = $settings[C::KEY_PRIVATE_PATH_OR_KEY_VALUE] ?? null; |
|
| 48 | if (empty($keyOrPath) === true) { |
|
| 49 | throw new CryptConfigurationException(); |
|
| 50 | } |
|
| 51 | ||
| 52 | $crypt = new PrivateKeyAsymmetricEncrypt($keyOrPath); |
|
| 53 | ||
| 54 | return $crypt; |
|
| 55 | }; |
|
| 56 | ||
| 57 | $container[DecryptInterface::class] = function (PsrContainerInterface $container): DecryptInterface { |
|
| 58 | $settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 59 | $keyOrPath = $settings[C::KEY_PUBLIC_PATH_OR_KEY_VALUE] ?? null; |
|
| 60 | if (empty($keyOrPath) === true) { |
|
| 61 | throw new CryptConfigurationException(); |
|
| 62 | } |
|
| 63 | ||
| 64 | $crypt = new PublicKeyAsymmetricDecrypt($keyOrPath); |
|
| 65 | ||
| 66 | return $crypt; |
|
| 67 | }; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||
| @@ 35-69 (lines=35) @@ | ||
| 32 | /** |
|
| 33 | * @package Limoncello\Crypt |
|
| 34 | */ |
|
| 35 | class AsymmetricPublicEncryptPrivateDecryptContainerConfigurator implements ContainerConfiguratorInterface |
|
| 36 | { |
|
| 37 | /** @var callable */ |
|
| 38 | const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME]; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @inheritdoc |
|
| 42 | */ |
|
| 43 | public static function configureContainer(LimoncelloContainerInterface $container): void |
|
| 44 | { |
|
| 45 | $container[EncryptInterface::class] = function (PsrContainerInterface $container): EncryptInterface { |
|
| 46 | $settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 47 | $keyOrPath = $settings[C::KEY_PUBLIC_PATH_OR_KEY_VALUE] ?? null; |
|
| 48 | if (empty($keyOrPath) === true) { |
|
| 49 | throw new CryptConfigurationException(); |
|
| 50 | } |
|
| 51 | ||
| 52 | $crypt = new PublicKeyAsymmetricEncrypt($keyOrPath); |
|
| 53 | ||
| 54 | return $crypt; |
|
| 55 | }; |
|
| 56 | ||
| 57 | $container[DecryptInterface::class] = function (PsrContainerInterface $container): DecryptInterface { |
|
| 58 | $settings = $container->get(SettingsProviderInterface::class)->get(C::class); |
|
| 59 | $keyOrPath = $settings[C::KEY_PRIVATE_PATH_OR_KEY_VALUE] ?? null; |
|
| 60 | if (empty($keyOrPath) === true) { |
|
| 61 | throw new CryptConfigurationException(); |
|
| 62 | } |
|
| 63 | ||
| 64 | $crypt = new PrivateKeyAsymmetricDecrypt($keyOrPath); |
|
| 65 | ||
| 66 | return $crypt; |
|
| 67 | }; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||