Skip to content

Commit 5791e4a

Browse files
committed
Include Cipher In Sodium classname
Unlike mcrypt, the sodium extension uses a different [en|de]crypt function for each avaiable cipher. Including the cipher in the class name provides a method for changing the chosen sodium cipher.
1 parent ae3f454 commit 5791e4a

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

lib/internal/Magento/Framework/Encryption/Adapter/Sodium.php renamed to lib/internal/Magento/Framework/Encryption/Adapter/SodiumChachaIetf.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
namespace Magento\Framework\Encryption\Adapter;
66

7-
use Magento\Framework\Encryption\Encryptor;
8-
97
/**
108
* Sodium adapter for encrypting and decrypting strings
119
*/
12-
class Sodium implements EncryptionAdapterInterface
10+
class SodiumChachaIetf implements EncryptionAdapterInterface
1311
{
1412
/**
1513
* @var string

lib/internal/Magento/Framework/Encryption/Encryptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\Encryption\Adapter\EncryptionAdapterInterface;
1313
use Magento\Framework\Encryption\Helper\Security;
1414
use Magento\Framework\Math\Random;
15-
use Magento\Framework\Encryption\Adapter\Sodium;
15+
use Magento\Framework\Encryption\Adapter\SodiumChachaIetf;
1616
use Magento\Framework\Encryption\Adapter\Mcrypt;
1717

1818
/**
@@ -274,7 +274,7 @@ private function getPasswordVersion()
274274
*/
275275
public function encrypt($data)
276276
{
277-
$crypt = new Sodium($this->keys[$this->keyVersion]);
277+
$crypt = new SodiumChachaIetf($this->keys[$this->keyVersion]);
278278

279279
return $this->keyVersion .
280280
':' . self::CIPHER_AEAD_CHACHA20POLY1305 .
@@ -408,7 +408,7 @@ private function getCrypt(
408408
$cipherVersion = $this->validateCipher($cipherVersion);
409409

410410
if ($cipherVersion >= self::CIPHER_AEAD_CHACHA20POLY1305) {
411-
return new Sodium($key);
411+
return new SodiumChachaIetf($key);
412412
}
413413

414414
if ($cipherVersion === self::CIPHER_RIJNDAEL_128) {

lib/internal/Magento/Framework/Encryption/Test/Unit/EncryptorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Framework\Encryption\Test\Unit;
1010

1111
use Magento\Framework\Encryption\Adapter\Mcrypt;
12-
use Magento\Framework\Encryption\Adapter\Sodium;
12+
use Magento\Framework\Encryption\Adapter\SodiumChachaIetf;
1313
use Magento\Framework\Encryption\Encryptor;
1414
use Magento\Framework\Encryption\Crypt;
1515
use Magento\Framework\App\DeploymentConfig;
@@ -159,7 +159,7 @@ public function testEncrypt()
159159
$parts = explode(':', $actual, 3);
160160
list(, , $encryptedData) = $parts;
161161

162-
$crypt = new Sodium(self::CRYPT_KEY_1);
162+
$crypt = new SodiumChachaIetf(self::CRYPT_KEY_1);
163163
// Verify decrypted matches original data
164164
$this->assertEquals($data, $crypt->decrypt(base64_decode((string)$encryptedData)));
165165
}

0 commit comments

Comments
 (0)