Skip to content

Commit 3640bc4

Browse files
StephenClouseNyholm
authored andcommitted
Fix issues with binary data being stored (#188)
* Ignore binary integration tests for Void adapter * Add common trait for armoring binary data in JSON * Armor binary data in MongoDB adapter * Armor binary data in encryption layer * Update IntegrationSimpleCacheTest.php
1 parent 735c5ad commit 3640bc4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

EncryptedItemDecorator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Cache\Encryption;
1313

14+
use Cache\Adapter\Common\JsonBinaryArmoring;
1415
use Cache\TagInterop\TaggableCacheItemInterface;
1516
use Defuse\Crypto\Crypto;
1617
use Defuse\Crypto\Key;
@@ -22,6 +23,8 @@
2223
*/
2324
class EncryptedItemDecorator implements TaggableCacheItemInterface
2425
{
26+
use JsonBinaryArmoring;
27+
2528
/**
2629
* The cacheItem should always contain encrypted data.
2730
*
@@ -67,11 +70,11 @@ public function set($value)
6770
{
6871
$type = gettype($value);
6972

70-
if ($type === 'object') {
73+
if ($type === 'object' || $type === 'array') {
7174
$value = serialize($value);
7275
}
7376

74-
$json = json_encode(['type' => $type, 'value' => $value]);
77+
$json = json_encode(['type' => $type, 'value' => static::jsonArmor($value)]);
7578

7679
$this->cacheItem->set(Crypto::encrypt($json, $this->key));
7780

@@ -155,11 +158,11 @@ public function __clone()
155158
*/
156159
private function transform(array $item)
157160
{
158-
if ($item['type'] === 'object') {
159-
return unserialize($item['value']);
160-
}
161+
$value = static::jsonDeArmor($item['value']);
161162

162-
$value = $item['value'];
163+
if ($item['type'] === 'object' || $item['type'] === 'array') {
164+
return unserialize($value);
165+
}
163166

164167
settype($value, $item['type']);
165168

0 commit comments

Comments
 (0)