Conditions | 1 |
Paths | 1 |
Total Lines | 106 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
135 | public function testMultipleRecipientEncryptionBis() |
||
136 | { |
||
137 | $expected_payload = "You can trust us to stick with you through thick and thin\xe2\x80\x93to the bitter end. And you can trust us to keep any secret of yours\xe2\x80\x93closer than you keep it yourself. But you cannot trust us to let you face trouble alone, and go off without a word. We are your friends, Frodo."; |
||
138 | |||
139 | $recipient_1_private_key = new JWK([ |
||
140 | 'kty' => 'RSA', |
||
141 | 'kid' => '[email protected]', |
||
142 | 'use' => 'enc', |
||
143 | 'n' => 'maxhbsmBtdQ3CNrKvprUE6n9lYcregDMLYNeTAWcLj8NnPU9XIYegTHVHQjxKDSHP2l-F5jS7sppG1wgdAqZyhnWvXhYNvcM7RfgKxqNx_xAHx6f3yy7s-M9PSNCwPC2lh6UAkR4I00EhV9lrypM9Pi4lBUop9t5fS9W5UNwaAllhrd-osQGPjIeI1deHTwx-ZTHu3C60Pu_LJIl6hKn9wbwaUmA4cR5Bd2pgbaY7ASgsjCUbtYJaNIHSoHXprUdJZKUMAzV0WOKPfA6OPI4oypBadjvMZ4ZAj3BnXaSYsEZhaueTXvZB4eZOAjIyh2e_VOIKVMsnDrJYAVotGlvMQ', |
||
144 | 'e' => 'AQAB', |
||
145 | 'd' => 'Kn9tgoHfiTVi8uPu5b9TnwyHwG5dK6RE0uFdlpCGnJN7ZEi963R7wybQ1PLAHmpIbNTztfrheoAniRV1NCIqXaW_qS461xiDTp4ntEPnqcKsyO5jMAji7-CL8vhpYYowNFvIesgMoVaPRYMYT9TW63hNM0aWs7USZ_hLg6Oe1mY0vHTI3F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beL6fG9mkDcIyPrBXx2bQ_mM', |
||
151 | ]); |
||
152 | |||
153 | $recipient_2_public_key = new JWK([ |
||
154 | 'kty' => 'EC', |
||
155 | 'kid' => '[email protected]', |
||
156 | 'use' => 'enc', |
||
157 | 'crv' => 'P-384', |
||
158 | 'x' => 'YU4rRUzdmVqmRtWOs2OpDE_T5fsNIodcG8G5FWPrTPMyxpzsSOGaQLpe2FpxBmu2', |
||
159 | 'y' => 'A8-yxCHxkfBz3hKZfI1jUYMjUhsEveZ9THuwFjH2sCNdtksRJU7D5-SkgaFL1ETP', |
||
160 | ]); |
||
161 | |||
162 | $recipient_2_private_key = new JWK([ |
||
163 | 'kty' => 'EC', |
||
164 | 'kid' => '[email protected]', |
||
165 | 'use' => 'enc', |
||
166 | 'crv' => 'P-384', |
||
167 | 'x' => 'YU4rRUzdmVqmRtWOs2OpDE_T5fsNIodcG8G5FWPrTPMyxpzsSOGaQLpe2FpxBmu2', |
||
168 | 'y' => 'A8-yxCHxkfBz3hKZfI1jUYMjUhsEveZ9THuwFjH2sCNdtksRJU7D5-SkgaFL1ETP', |
||
169 | 'd' => 'iTx2pk7wW-GqJkHcEkFQb2EFyYcO7RugmaW3mRrQVAOUiPommT0IdnYK2xDlZh-j', |
||
170 | ]); |
||
171 | |||
172 | $recipient_3_private_key = new JWK([ |
||
173 | 'kty' => 'oct', |
||
174 | 'kid' => '18ec08e1-bfa9-4d95-b205-2b4dd1d4321d', |
||
175 | 'use' => 'enc', |
||
176 | 'alg' => 'A256GCMKW', |
||
177 | 'k' => 'qC57l_uxcm7Nm3K-ct4GFjx8tM1U8CZ0NLBvdQstiS8', |
||
178 | ]); |
||
179 | |||
180 | $protected_headers = [ |
||
181 | 'enc' => 'A128CBC-HS256', |
||
182 | ]; |
||
183 | |||
184 | $headers = [ |
||
185 | 'cty' => 'text/plain', |
||
186 | ]; |
||
187 | |||
188 | $recipient_1_headers = [ |
||
189 | 'alg' => 'RSA1_5', |
||
190 | 'kid' => '[email protected]', |
||
191 | ]; |
||
192 | |||
193 | $recipient_2_headers = [ |
||
194 | 'alg' => 'ECDH-ES+A256KW', |
||
195 | 'kid' => '[email protected]', |
||
196 | ]; |
||
197 | |||
198 | $recipient_3_headers = [ |
||
199 | 'alg' => 'A256GCMKW', |
||
200 | 'kid' => '18ec08e1-bfa9-4d95-b205-2b4dd1d4321d', |
||
201 | ]; |
||
202 | |||
203 | $jwe = JWEFactory::createJWE($expected_payload, $protected_headers, $headers); |
||
204 | $encrypter = EncrypterFactory::createEncrypter(['RSA1_5', 'ECDH-ES+A256KW', 'A256GCMKW', 'A128CBC-HS256']); |
||
205 | |||
206 | $jwe = $jwe->addRecipient( |
||
207 | $recipient_1_private_key, |
||
208 | $recipient_1_headers |
||
209 | ); |
||
210 | $jwe = $jwe->addRecipient( |
||
211 | $recipient_2_public_key, |
||
212 | $recipient_2_headers |
||
213 | ); |
||
214 | $jwe = $jwe->addRecipient( |
||
215 | $recipient_3_private_key, |
||
216 | $recipient_3_headers |
||
217 | ); |
||
218 | |||
219 | $encrypter->encrypt($jwe); |
||
220 | |||
221 | $decrypter = DecrypterFactory::createDecrypter(['RSA1_5', 'ECDH-ES+A256KW', 'A256GCMKW', 'A128CBC-HS256']); |
||
222 | |||
223 | $loaded_json = Loader::load($jwe->toJSON()); |
||
224 | $decrypter->decryptUsingKey($loaded_json, $recipient_1_private_key); |
||
225 | |||
226 | $loaded_json = Loader::load($jwe->toJSON()); |
||
227 | $decrypter->decryptUsingKey($loaded_json, $recipient_2_private_key); |
||
228 | |||
229 | $loaded_json = Loader::load($jwe->toJSON()); |
||
230 | $decrypter->decryptUsingKey($loaded_json, $recipient_3_private_key); |
||
231 | |||
232 | $this->assertEquals($protected_headers, $loaded_json->getSharedProtectedHeaders()); |
||
233 | $this->assertEquals($recipient_1_headers, $loaded_json->getRecipient(0)->getHeaders()); |
||
234 | $this->assertTrue(array_key_exists('epk', $loaded_json->getRecipient(1)->getHeaders())); |
||
235 | $this->assertTrue(array_key_exists('iv', $loaded_json->getRecipient(2)->getHeaders())); |
||
236 | $this->assertTrue(array_key_exists('tag', $loaded_json->getRecipient(2)->getHeaders())); |
||
237 | $this->assertEquals($headers, $loaded_json->getSharedHeaders()); |
||
238 | |||
239 | $this->assertEquals($expected_payload, $loaded_json->getPayload()); |
||
240 | } |
||
241 | } |
||
242 |