Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
absolute-quantum committed May 14, 2017
1 parent a78083b commit 18c0c1b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
28 changes: 14 additions & 14 deletions Encryptors/DefuseEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ public function __construct($oDoctrineEncryptSubscriber)
$this->fs = new Filesystem();
}

private function getKey()
{
if ($this->encryptionKey === null) {
if ($this->fs->exists($this->fullStorePath)) {
$this->encryptionKey = file_get_contents($this->fullStorePath);
} else {
$this->encryptionKey = $this->oDoctrineEncryptSubscriber->generateRandomString();
$this->fs->dumpFile($this->fullStorePath, $this->encryptionKey);
}
}

return $this->encryptionKey;
}

/**
* {@inheritdoc}
*/
Expand All @@ -55,4 +41,18 @@ public function decrypt($data)
{
return \Defuse\Crypto\Crypto::decryptWithPassword($data, $this->getKey());
}

private function getKey()
{
if ($this->encryptionKey === null) {
if ($this->fs->exists($this->fullStorePath)) {
$this->encryptionKey = file_get_contents($this->fullStorePath);
} else {
$this->encryptionKey = $this->oDoctrineEncryptSubscriber->generateRandomString();
$this->fs->dumpFile($this->fullStorePath, $this->encryptionKey);
}
}

return $this->encryptionKey;
}
}
28 changes: 14 additions & 14 deletions Encryptors/HaliteEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ public function __construct($oDoctrineEncryptSubscriber)
$this->fullStorePath = $this->storeInDir . $this->fileName;
}

private function getKey()
{
if ($this->encryptionKey === null) {
try {
$this->encryptionKey = \ParagonIE\Halite\KeyFactory::loadEncryptionKey($this->fullStorePath);
} catch (\ParagonIE\Halite\Alerts\CannotPerformOperation $e) {
$this->encryptionKey = KeyFactory::generateEncryptionKey();
\ParagonIE\Halite\KeyFactory::save($encryptionKey, $this->fullStorePath);
}
}

return $this->encryptionKey;
}

/**
* {@inheritdoc}
*/
Expand All @@ -58,4 +44,18 @@ public function decrypt($data)
{
return \ParagonIE\Halite\Symmetric\Crypto::decrypt($data, $this->getKey());
}

private function getKey()
{
if ($this->encryptionKey === null) {
try {
$this->encryptionKey = \ParagonIE\Halite\KeyFactory::loadEncryptionKey($this->fullStorePath);
} catch (\ParagonIE\Halite\Alerts\CannotPerformOperation $e) {
$this->encryptionKey = KeyFactory::generateEncryptionKey();
\ParagonIE\Halite\KeyFactory::save($this->encryptionKey, $this->fullStorePath);
}
}

return $this->encryptionKey;
}
}
6 changes: 5 additions & 1 deletion Subscribers/DoctrineEncryptSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public function __construct(Reader $annReader, $encryptorClass, EncryptorInterfa

$this->projectRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;

$encryptorClass = '\\Ambta\\DoctrineEncryptBundle\\Encryptors\\' . ucfirst($encryptorClass) . 'Encryptor';
if (class_exists(ucfirst($encryptorClass)) === false) {
$encryptorClass = '\\Ambta\\DoctrineEncryptBundle\\Encryptors\\' . ucfirst($encryptorClass) . 'Encryptor';
} else {
$encryptorClass = ucfirst($encryptorClass);
}

if ($service instanceof EncryptorInterface) {
$this->encryptor = $service;
Expand Down

0 comments on commit 18c0c1b

Please sign in to comment.