7 declare(strict_types=1);
18 private static $cipherInfo;
20 private const SUPPORTED_CIPHER_MODE_COMBINATIONS = [
21 MCRYPT_BLOWFISH => [MCRYPT_MODE_ECB],
22 MCRYPT_RIJNDAEL_128 => [MCRYPT_MODE_ECB],
23 MCRYPT_RIJNDAEL_256 => [MCRYPT_MODE_CBC],
28 $this->key = substr(__CLASS__, -32, 32);
37 }
while (strlen(
$result) < $length);
39 return substr(
$result, -$length);
42 private function requireCipherInfo()
44 $filename =
__DIR__ .
'/../Crypt/_files/_cipher_info.php';
46 if (!self::$cipherInfo) {
47 self::$cipherInfo = include $filename;
51 private function getKeySize(
string $cipherName,
string $modeName): int
53 $this->requireCipherInfo();
54 return self::$cipherInfo[$cipherName][$modeName][
'key_size'];
57 private function getInitVectorSize(
string $cipherName,
string $modeName): int
59 $this->requireCipherInfo();
60 return self::$cipherInfo[$cipherName][$modeName][
'iv_size'];
63 public function getCipherModeCombinations(): array
66 foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
68 foreach ($modes as
$mode) {
83 $crypt = new \Magento\Framework\Encryption\Adapter\Mcrypt($this->key, $cipher,
$mode,
$initVector);
85 $this->assertEquals($cipher, $crypt->getCipher());
86 $this->assertEquals(
$mode, $crypt->getMode());
87 $this->assertEquals(
$initVector, $crypt->getInitVector());
90 public function getConstructorExceptionData(): array
92 $key = substr(__CLASS__, -32, 32);
94 foreach (self::SUPPORTED_CIPHER_MODE_COMBINATIONS as $cipher => $modes) {
96 foreach ($modes as
$mode) {
97 $tooLongKey = str_repeat(
'-', $this->getKeySize($cipher,
$mode) + 1);
98 $tooShortInitVector = str_repeat(
'-', $this->getInitVectorSize($cipher,
$mode) - 1);
99 $tooLongInitVector = str_repeat(
'-', $this->getInitVectorSize($cipher,
$mode) + 1);
100 $result[
'tooLongKey-' . $cipher .
'-' .
$mode .
'-false'] = [$tooLongKey, $cipher,
$mode,
false];
101 $keyPrefix =
'key-' . $cipher .
'-' .
$mode;
102 $result[$keyPrefix .
'-tooShortInitVector'] = [$key, $cipher,
$mode, $tooShortInitVector];
103 $result[$keyPrefix .
'-tooLongInitVector'] = [$key, $cipher,
$mode, $tooLongInitVector];
115 new \Magento\Framework\Encryption\Adapter\Mcrypt($key, $cipher,
$mode,
$initVector);
120 $cryptExpected = new \Magento\Framework\Encryption\Adapter\Mcrypt(
126 $cryptActual = new \Magento\Framework\Encryption\Adapter\Mcrypt($this->key);
128 $this->assertEquals($cryptExpected->getCipher(), $cryptActual->getCipher());
129 $this->assertEquals($cryptExpected->getMode(), $cryptActual->getMode());
130 $this->assertEquals($cryptExpected->getInitVector(), $cryptActual->getInitVector());
135 $fixturesFilename =
__DIR__ .
'/../Crypt/_files/_crypt_fixtures.php';
137 $result = include $fixturesFilename;
139 foreach (
$result as &$cryptParams) {
140 $cryptParams[5] = base64_decode($cryptParams[5]);
155 string $expectedData,
158 $crypt = new \Magento\Framework\Encryption\Adapter\Mcrypt($key, $cipher,
$mode,
$initVector);
159 $actualData = $crypt->decrypt($inputData);
160 $this->assertEquals($expectedData, $actualData);
168 $crypt = new \Magento\Framework\Encryption\Adapter\Mcrypt(
174 $actualInitVector = $crypt->getInitVector();
176 $expectedInitVector = str_repeat(
"\0", $this->getInitVectorSize($cipher,
$mode));
177 $this->assertEquals($expectedInitVector, $actualInitVector);
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testConstructor(string $cipher, string $mode)
testDecrypt(string $key, string $cipher, string $mode, ?string $initVector, string $expectedData, string $inputData)
testConstructorDefaults()
testConstructorException(string $key, string $cipher, string $mode, ?string $initVector=null)
testInitVectorNone(string $cipher, string $mode)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
getRandomString(int $length)