1 | <?php |
||
6 | abstract class EncryptingDecorator implements Cache |
||
7 | { |
||
8 | use EncryptionStatsTrait; |
||
9 | |||
10 | /** @var Cache */ |
||
11 | protected $decorated; |
||
12 | |||
13 | /** |
||
14 | 177 | * @param Cache $decorated |
|
15 | */ |
||
16 | 177 | public function __construct(Cache $decorated) |
|
20 | |||
21 | /** |
||
22 | 78 | * {@inheritdoc} |
|
23 | */ |
||
24 | 78 | public function fetch($id) |
|
35 | 72 | ||
36 | /** |
||
37 | 72 | * {@inheritdoc} |
|
38 | 72 | */ |
|
39 | public function save($id, $data, $ttl = 0) |
||
40 | { |
||
41 | return $this->decorated->save( |
||
42 | $id, |
||
43 | $this->callAndTime([$this, 'encrypt'], [$data, $id]), |
||
44 | 42 | $ttl |
|
45 | ); |
||
46 | 42 | } |
|
47 | 36 | ||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | 6 | */ |
|
51 | public function contains($id) |
||
59 | 6 | ||
60 | 3 | /** |
|
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function getStats() |
||
67 | 6 | ||
68 | 6 | /** |
|
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 36 | public function delete($id) |
|
76 | |||
77 | protected function hmac(string $encrypted, string $id): string |
||
81 | |||
82 | 72 | protected function generateIv(string $method): string |
|
86 | 72 | ||
87 | protected function encipher( |
||
95 | |||
96 | 36 | protected function decipher( |
|
104 | |||
105 | abstract protected function encrypt($data, string $id): EncryptedValue; |
||
106 | |||
107 | abstract protected function decrypt($data); |
||
108 | |||
109 | abstract protected function isDataDecryptable($data, string $id): bool; |
||
110 | } |
||
111 |