8000 Merge branch '4.4' · symfony/framework-bundle@4fc9f72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4fc9f72

Browse files
Merge branch '4.4'
* 4.4: [FrameworkBundle] allow using secrets when the sodium ext is missing [TwigBridge] Fix switch-custom changelog entry
2 parents 3ac4e92 + d4b5173 commit 4fc9f72

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed 8000

Secrets/SodiumVault.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class SodiumVault extends AbstractVault
3030
*/
3131
public function __construct(string $secretsDir, $decryptionKey = null)
3232
{
33-
if (!\function_exists('sodium_crypto_box_seal')) {
34-
throw new \LogicException('The "sodium" PHP extension is required to deal with secrets. Alternatively, try running "composer require paragonie/sodium_compat" if you cannot enable the extension."');
35-
}
36-
3733
if (null !== $decryptionKey && !\is_string($decryptionKey) && !(\is_object($decryptionKey) && method_exists($decryptionKey, '__toString'))) {
3834
throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, %s given.', \gettype($decryptionKey)));
3935
}
@@ -107,16 +103,22 @@ public function reveal(string $name): ?string
107103
return null;
108104
}
109105

106+
if (!\function_exists('sodium_crypto_box_seal')) {
107+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as the "sodium" PHP extension missing. Try running "composer require paragonie/sodium_compat" if you cannot enable the extension."', $name);
108+
109+
return null;
110+
}
111+
110112
$this->loadKeys();
111113

112114
if ('' === $this->decryptionKey) {
113-
$this->lastMessage = sprintf('Secrets cannot be revealed as no decryption key was found in "%s".', $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
115+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as no decryption key was found in "%s".', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
114116

115117
return null;
116118
}
117119

118120
if (false === $value = sodium_crypto_box_seal_open(include $file, $this->decryptionKey)) {
119-
$this->lastMessage = sprintf('Secrets cannot be revealed as the wrong decryption key was provided for "%s".', $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
121+
$this->lastMessage = sprintf('Secret "%s" cannot be revealed as the wrong decryption key was provided for "%s".', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
120122

121123
return null;
122124
}
@@ -167,6 +169,10 @@ public function list(bool $reveal = false): array
167169

168170
private function loadKeys(): void
169171
{
172+
if (!\function_exists('sodium_crypto_box_seal')) {
173+
throw new \LogicException('The "sodium" PHP extension is required to deal with secrets. Alternatively, try running "composer require paragonie/sodium_compat" if you cannot enable the extension."');
174+
}
175+
170176
if (null !== $this->encryptionKey || '' !== $this->decryptionKey = (string) $this->decryptionKey) {
171177
return;
172178
}

0 commit comments

Comments
 (0)
0