1 | <?php |
||
32 | final class JWELoader |
||
33 | { |
||
34 | /** |
||
35 | * @var HeaderCheckerManager |
||
36 | */ |
||
37 | private $headerCheckerManager; |
||
38 | |||
39 | /** |
||
40 | * @var AlgorithmManager |
||
41 | */ |
||
42 | private $keyEncryptionAlgorithmManager; |
||
43 | |||
44 | /** |
||
45 | * @var AlgorithmManager |
||
46 | */ |
||
47 | private $contentEncryptionAlgorithmManager; |
||
48 | |||
49 | /** |
||
50 | * @var CompressionMethodManager |
||
51 | */ |
||
52 | private $compressionMethodManager; |
||
53 | |||
54 | /** |
||
55 | * JWELoader constructor. |
||
56 | * |
||
57 | * @param AlgorithmManager $keyEncryptionAlgorithmManager |
||
58 | * @param AlgorithmManager $contentEncryptionAlgorithmManager |
||
59 | * @param CompressionMethodManager $compressionMethodManager |
||
60 | * @param HeaderCheckerManager $headerCheckerManager |
||
61 | */ |
||
62 | public function __construct(AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionMethodManager, HeaderCheckerManager $headerCheckerManager) |
||
69 | |||
70 | /** |
||
71 | * @param string $input |
||
72 | * |
||
73 | * @return JWE |
||
74 | */ |
||
75 | public function load(string $input): JWE |
||
79 | |||
80 | /** |
||
81 | * @return string[] |
||
82 | */ |
||
83 | public function getSupportedCompressionMethods(): array |
||
87 | |||
88 | /** |
||
89 | * @return string[] |
||
90 | */ |
||
91 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
95 | |||
96 | /** |
||
97 | * @return string[] |
||
98 | */ |
||
99 | public function getSupportedContentEncryptionAlgorithms(): array |
||
103 | |||
104 | /** |
||
105 | * @param JWE $jwe A JWE object to decrypt |
||
106 | * @param JWK $jwk The key used to decrypt the input |
||
107 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
108 | * |
||
109 | * @return JWE |
||
110 | */ |
||
111 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
117 | |||
118 | /** |
||
119 | * @param JWE $jwe A JWE object to decrypt |
||
120 | * @param JWKSet $jwkset The key set used to decrypt the input |
||
121 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
122 | * |
||
123 | * @return JWE |
||
124 | */ |
||
125 | public function decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
144 | |||
145 | /** |
||
146 | * @param JWE $jwe |
||
147 | * @param JWKSet $jwkset |
||
148 | * @param int $i |
||
149 | * |
||
150 | * @return string|null |
||
151 | */ |
||
152 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
181 | |||
182 | /** |
||
183 | * @param JWE $jwe |
||
184 | */ |
||
185 | private function checkRecipients(JWE $jwe) |
||
191 | |||
192 | /** |
||
193 | * @param JWE $jwe |
||
194 | */ |
||
195 | private function checkPayload(JWE $jwe) |
||
201 | |||
202 | /** |
||
203 | * @param JWKSet $jwkset |
||
204 | */ |
||
205 | private function checkJWKSet(JWKSet $jwkset) |
||
211 | |||
212 | /** |
||
213 | * @param AlgorithmInterface $key_encryption_algorithm |
||
214 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
215 | * @param JWK $key |
||
216 | * @param Recipient $recipient |
||
217 | * @param array $complete_headers |
||
218 | * |
||
219 | * @return null|string |
||
220 | */ |
||
221 | private function decryptCEK(AlgorithmInterface $key_encryption_algorithm, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
237 | |||
238 | /** |
||
239 | * @param JWE $jwe |
||
240 | * @param string $cek |
||
241 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
242 | * @param array $complete_headers |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array $complete_headers): string |
||
255 | |||
256 | /** |
||
257 | * @param string $payload |
||
258 | * @param array $complete_headers |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
274 | |||
275 | /** |
||
276 | * @param array $complete_headers |
||
277 | * |
||
278 | * @throws \InvalidArgumentException |
||
279 | */ |
||
280 | private function checkCompleteHeader(array $complete_headers) |
||
288 | |||
289 | /** |
||
290 | * @param array $complete_headers |
||
291 | * |
||
292 | * @return KeyEncryptionAlgorithmInterface |
||
293 | */ |
||
294 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithmInterface |
||
303 | |||
304 | /** |
||
305 | * @param array $complete_headers |
||
306 | * |
||
307 | * @return ContentEncryptionAlgorithmInterface |
||
308 | */ |
||
309 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithmInterface |
||
318 | } |
||
319 |
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: