forked from VincentChalnot/SidusEncryptionBundle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from cleverage/feature/add-way-to-disable-encry…
…ption Add a enabler to allow values to not be decrypted or encrypted temporary
- Loading branch information
Showing
11 changed files
with
283 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Sidus\EncryptionBundle\Doctrine\Type\Behavior; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Sidus\EncryptionBundle\Encryption\Enabler\EncryptionEnablerInterface; | ||
use Sidus\EncryptionBundle\Manager\EncryptionManagerInterface; | ||
|
||
trait EncryptType | ||
{ | ||
private EncryptionManagerInterface $encryptionManager; | ||
private EncryptionEnablerInterface $encryptionEnabler; | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
// Allow to do not decrypt the value for the current request | ||
if (!$this->encryptionEnabler->isEncryptionEnabled()) { | ||
return $value; | ||
} | ||
|
||
return $this->encryptionManager->decryptString(base64_decode($value)); | ||
} | ||
|
||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
// Allow to do not decrypt the value for the current request | ||
if (!$this->encryptionEnabler->isEncryptionEnabled()) { | ||
return $value; | ||
} | ||
$value = $this->encryptionManager->encryptString($value); | ||
|
||
return base64_encode($value); | ||
} | ||
|
||
public function setEncryptionManager(EncryptionManagerInterface $encryptionManager): void | ||
{ | ||
$this->encryptionManager = $encryptionManager; | ||
} | ||
|
||
public function setEncryptionEnabler(EncryptionEnablerInterface $encryptionEnabler): void | ||
{ | ||
$this->encryptionEnabler = $encryptionEnabler; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Sidus\EncryptionBundle\Encryption\Enabler; | ||
|
||
class EncryptionEnabler implements EncryptionEnablerInterface | ||
{ | ||
/** | ||
* By default the encryption is enabled. | ||
* | ||
* @var bool | ||
*/ | ||
private bool $enabled = true; | ||
|
||
public function enableEncryption(): void | ||
{ | ||
$this->enabled = true; | ||
} | ||
|
||
public function disableEncryption(): void | ||
{ | ||
$this->enabled = false; | ||
} | ||
|
||
public function isEncryptionEnabled(): bool | ||
{ | ||
return $this->enabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Sidus\EncryptionBundle\Encryption\Enabler; | ||
|
||
interface EncryptionEnablerInterface | ||
{ | ||
/** | ||
* Enable the encryption for the current request. | ||
*/ | ||
public function enableEncryption(): void; | ||
|
||
/** | ||
* Disable the encryption for the current request. | ||
*/ | ||
public function disableEncryption(): void; | ||
|
||
/** | ||
* Return if the encryption is enabled in the current request. | ||
* | ||
* @return bool | ||
*/ | ||
public function isEncryptionEnabled(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.