1 | <?php |
||
20 | class Encryptor implements EncryptorInterface |
||
21 | { |
||
22 | /** |
||
23 | * Array key of encryption key in deployment config |
||
24 | */ |
||
25 | const PARAM_CRYPT_KEY = 'options/encryption_key'; |
||
26 | |||
27 | /**#@+ |
||
28 | * Cipher versions |
||
29 | */ |
||
30 | const CIPHER_BLOWFISH = 0; |
||
31 | |||
32 | const CIPHER_RIJNDAEL_128 = 1; |
||
33 | |||
34 | const CIPHER_RIJNDAEL_256 = 2; |
||
35 | |||
36 | const CIPHER_LATEST = 2; |
||
37 | /**#@-*/ |
||
38 | |||
39 | /** |
||
40 | * Indicate cipher |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $cipher = self::CIPHER_LATEST; |
||
45 | |||
46 | /** |
||
47 | * Version of encryption key |
||
48 | * |
||
49 | * @var int |
||
50 | */ |
||
51 | protected $keyVersion; |
||
52 | |||
53 | /** |
||
54 | * Array of encryption keys |
||
55 | * |
||
56 | * @var string[] |
||
57 | */ |
||
58 | protected $keys = []; |
||
59 | |||
60 | /** |
||
61 | * Random generator |
||
62 | * |
||
63 | * @var Random |
||
64 | */ |
||
65 | protected $random; |
||
66 | |||
67 | /** |
||
68 | * @param Random $random |
||
69 | * @param Configuration $configuration |
||
70 | */ |
||
71 | public function __construct( |
||
81 | |||
82 | /** |
||
83 | * Check whether specified cipher version is supported |
||
84 | * |
||
85 | * Returns matched supported version or throws exception |
||
86 | * |
||
87 | * @param int $version |
||
88 | * |
||
89 | * @return int |
||
90 | * @throws \Exception |
||
91 | */ |
||
92 | public function validateCipher($version) |
||
102 | |||
103 | /** |
||
104 | * Prepend key and cipher versions to encrypted data after encrypting |
||
105 | * |
||
106 | * @param string $data |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function encrypt($data) |
||
121 | |||
122 | /** |
||
123 | * Look for key and crypt versions in encrypted data before decrypting |
||
124 | * |
||
125 | * Unsupported/unspecified key version silently fallback to the oldest we have |
||
126 | * Unsupported cipher versions eventually throw exception |
||
127 | * Unspecified cipher version fallback to the oldest we support |
||
128 | * |
||
129 | * @param string $data |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function decrypt($data) |
||
176 | |||
177 | /** |
||
178 | * Return crypt model, instantiate if it is empty |
||
179 | * |
||
180 | * @param string|null $key NULL value means usage of the default key specified on constructor |
||
181 | * |
||
182 | * @return \Gojira\Framework\Encryption\Crypt |
||
183 | * @throws \Exception |
||
184 | */ |
||
185 | public function validateKey($key) |
||
192 | |||
193 | /** |
||
194 | * Attempt to append new key & version |
||
195 | * |
||
196 | * @param string $key |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function setNewKey($key) |
||
207 | |||
208 | /** |
||
209 | * Export current keys as string |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function exportKeys() |
||
217 | |||
218 | /** |
||
219 | * Initialize crypt module if needed |
||
220 | * |
||
221 | * By default initializes with latest key and crypt versions |
||
222 | * |
||
223 | * @param string $key |
||
224 | * @param int $cipherVersion |
||
225 | * @param bool $initVector |
||
226 | * |
||
227 | * @return Crypt|null |
||
228 | */ |
||
229 | protected function getCrypt($key = null, $cipherVersion = null, $initVector = true) |
||
261 | } |
||
262 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.