Skip to content

Commit

Permalink
Change how values are decrypted - resolves #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rawilk committed Oct 9, 2020
1 parent 55297e5 commit efb29ca
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rawilk\Settings;

use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
Expand Down Expand Up @@ -80,9 +81,7 @@ public function get(string $key, $default = null)
}

if ($value !== null && $value !== $default) {
$value = $this->unserializeValue(
$this->encryptionIsEnabled() ? $this->encrypter->decrypt($value) : $value
);
$value = $this->unserializeValue($this->decryptValue($value));
}

$this->context();
Expand Down Expand Up @@ -240,4 +239,17 @@ protected function encryptionIsEnabled(): bool
{
return $this->encryptionEnabled && $this->encrypter !== null;
}

protected function decryptValue($value)
{
if (! $this->encryptionIsEnabled()) {
return $value;
}

try {
return $this->encrypter->decrypt($value);
} catch (DecryptException $e) {
return $value;
}
}
}

0 comments on commit efb29ca

Please sign in to comment.