1 | <?php |
||
35 | final class JWEDecrypter |
||
36 | { |
||
37 | /** |
||
38 | * @var HeaderCheckerManager |
||
39 | */ |
||
40 | private $headerCheckerManager; |
||
41 | |||
42 | /** |
||
43 | * @var AlgorithmManager |
||
44 | */ |
||
45 | private $keyEncryptionAlgorithmManager; |
||
46 | |||
47 | /** |
||
48 | * @var AlgorithmManager |
||
49 | */ |
||
50 | private $contentEncryptionAlgorithmManager; |
||
51 | |||
52 | /** |
||
53 | * @var CompressionMethodManager |
||
54 | */ |
||
55 | private $compressionMethodManager; |
||
56 | |||
57 | /** |
||
58 | * JWEDecrypter constructor. |
||
59 | * |
||
60 | * @param AlgorithmManager $keyEncryptionAlgorithmManager |
||
61 | * @param AlgorithmManager $contentEncryptionAlgorithmManager |
||
62 | * @param CompressionMethodManager $compressionMethodManager |
||
63 | * @param HeaderCheckerManager $headerCheckerManager |
||
64 | */ |
||
65 | public function __construct(AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionMethodManager, HeaderCheckerManager $headerCheckerManager) |
||
72 | |||
73 | /** |
||
74 | * @return AlgorithmManager |
||
75 | */ |
||
76 | public function getKeyEncryptionAlgorithmManager(): AlgorithmManager |
||
80 | |||
81 | /** |
||
82 | * @return AlgorithmManager |
||
83 | */ |
||
84 | public function getContentEncryptionAlgorithmManager(): AlgorithmManager |
||
88 | |||
89 | /** |
||
90 | * @return CompressionMethodManager |
||
91 | */ |
||
92 | public function getCompressionMethodManager(): CompressionMethodManager |
||
96 | |||
97 | /** |
||
98 | * @param JWE $jwe A JWE object to decrypt |
||
99 | * @param JWK $jwk The key used to decrypt the input |
||
100 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
101 | * |
||
102 | * @return JWE |
||
103 | */ |
||
104 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
111 | |||
112 | /** |
||
113 | * @param JWE $jwe A JWE object to decrypt |
||
114 | * @param JWKSet $jwkset The key set used to decrypt the input |
||
115 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
116 | * |
||
117 | * @return JWE |
||
118 | */ |
||
119 | public function decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
143 | |||
144 | /** |
||
145 | * @param JWE $jwe |
||
146 | * @param JWKSet $jwkset |
||
147 | * @param int $i |
||
148 | * |
||
149 | * @return string|null |
||
150 | */ |
||
151 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
180 | |||
181 | /** |
||
182 | * @param JWE $jwe |
||
183 | */ |
||
184 | private function checkRecipients(JWE $jwe) |
||
190 | |||
191 | /** |
||
192 | * @param JWE $jwe |
||
193 | */ |
||
194 | private function checkPayload(JWE $jwe) |
||
200 | |||
201 | /** |
||
202 | * @param JWKSet $jwkset |
||
203 | */ |
||
204 | private function checkJWKSet(JWKSet $jwkset) |
||
210 | |||
211 | /** |
||
212 | * @param AlgorithmInterface $key_encryption_algorithm |
||
213 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
214 | * @param JWK $key |
||
215 | * @param Recipient $recipient |
||
216 | * @param array $complete_headers |
||
217 | * |
||
218 | * @return null|string |
||
219 | */ |
||
220 | private function decryptCEK(AlgorithmInterface $key_encryption_algorithm, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
236 | |||
237 | /** |
||
238 | * @param JWE $jwe |
||
239 | * @param string $cek |
||
240 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
241 | * @param array $complete_headers |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array $complete_headers): string |
||
254 | |||
255 | /** |
||
256 | * @param string $payload |
||
257 | * @param array $complete_headers |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
273 | |||
274 | /** |
||
275 | * @param array $complete_headers |
||
276 | * |
||
277 | * @throws \InvalidArgumentException |
||
278 | */ |
||
279 | private function checkCompleteHeader(array $complete_headers) |
||
287 | |||
288 | /** |
||
289 | * @param array $complete_headers |
||
290 | * |
||
291 | * @return KeyEncryptionAlgorithmInterface |
||
292 | */ |
||
293 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithmInterface |
||
302 | |||
303 | /** |
||
304 | * @param array $complete_headers |
||
305 | * |
||
306 | * @return ContentEncryptionAlgorithmInterface |
||
307 | */ |
||
308 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithmInterface |
||
317 | } |
||
318 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: