1 | <?php |
||
36 | final class JWELoader |
||
37 | { |
||
38 | /** |
||
39 | * @var HeaderCheckerManager |
||
40 | */ |
||
41 | private $headerCheckerManager; |
||
42 | |||
43 | /** |
||
44 | * @var AlgorithmManager |
||
45 | */ |
||
46 | private $keyEncryptionAlgorithmManager; |
||
47 | |||
48 | /** |
||
49 | * @var AlgorithmManager |
||
50 | */ |
||
51 | private $contentEncryptionAlgorithmManager; |
||
52 | |||
53 | /** |
||
54 | * @var CompressionMethodManager |
||
55 | */ |
||
56 | private $compressionMethodManager; |
||
57 | |||
58 | /** |
||
59 | * @var JWESerializerManager |
||
60 | */ |
||
61 | private $serializerManager; |
||
62 | |||
63 | /** |
||
64 | * JWELoader constructor. |
||
65 | * |
||
66 | * @param AlgorithmManager $keyEncryptionAlgorithmManager |
||
67 | * @param AlgorithmManager $contentEncryptionAlgorithmManager |
||
68 | * @param CompressionMethodManager $compressionMethodManager |
||
69 | * @param HeaderCheckerManager $headerCheckerManager |
||
70 | * @param JWESerializerManager $serializerManager |
||
71 | */ |
||
72 | public function __construct(AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionMethodManager, HeaderCheckerManager $headerCheckerManager, JWESerializerManager $serializerManager) |
||
80 | |||
81 | /** |
||
82 | * @param string $input |
||
83 | * @param string|null $serializer |
||
84 | * |
||
85 | * @return JWE |
||
86 | */ |
||
87 | public function load(string $input, ?string &$serializer = null): JWE |
||
91 | |||
92 | /** |
||
93 | * @return AlgorithmManager |
||
94 | */ |
||
95 | public function getKeyEncryptionAlgorithmManager(): AlgorithmManager |
||
99 | |||
100 | /** |
||
101 | * @return AlgorithmManager |
||
102 | */ |
||
103 | public function getContentEncryptionAlgorithmManager(): AlgorithmManager |
||
107 | |||
108 | /** |
||
109 | * @return CompressionMethodManager |
||
110 | */ |
||
111 | public function getCompressionMethodManager(): CompressionMethodManager |
||
115 | |||
116 | /** |
||
117 | * @param JWE $jwe A JWE object to decrypt |
||
118 | * @param JWK $jwk The key used to decrypt the input |
||
119 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
120 | * |
||
121 | * @return JWE |
||
122 | */ |
||
123 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
132 | |||
133 | /** |
||
134 | * @param JWE $jwe A JWE object to decrypt |
||
135 | * @param JWKSet $jwkset The key set used to decrypt the input |
||
136 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
137 | * |
||
138 | * @return JWE |
||
139 | */ |
||
140 | public function decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
159 | |||
160 | /** |
||
161 | * @param JWE $jwe |
||
162 | * @param JWKSet $jwkset |
||
163 | * @param int $i |
||
164 | * |
||
165 | * @return string|null |
||
166 | */ |
||
167 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
196 | |||
197 | /** |
||
198 | * @param JWE $jwe |
||
199 | */ |
||
200 | private function checkRecipients(JWE $jwe) |
||
206 | |||
207 | /** |
||
208 | * @param JWE $jwe |
||
209 | */ |
||
210 | private function checkPayload(JWE $jwe) |
||
216 | |||
217 | /** |
||
218 | * @param JWKSet $jwkset |
||
219 | */ |
||
220 | private function checkJWKSet(JWKSet $jwkset) |
||
226 | |||
227 | /** |
||
228 | * @param AlgorithmInterface $key_encryption_algorithm |
||
229 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
230 | * @param JWK $key |
||
231 | * @param Recipient $recipient |
||
232 | * @param array $complete_headers |
||
233 | * |
||
234 | * @return null|string |
||
235 | */ |
||
236 | private function decryptCEK(AlgorithmInterface $key_encryption_algorithm, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
252 | |||
253 | /** |
||
254 | * @param JWE $jwe |
||
255 | * @param string $cek |
||
256 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
257 | * @param array $complete_headers |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array $complete_headers): string |
||
270 | |||
271 | /** |
||
272 | * @param string $payload |
||
273 | * @param array $complete_headers |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
289 | |||
290 | /** |
||
291 | * @param array $complete_headers |
||
292 | * |
||
293 | * @throws \InvalidArgumentException |
||
294 | */ |
||
295 | private function checkCompleteHeader(array $complete_headers) |
||
303 | |||
304 | /** |
||
305 | * @param array $complete_headers |
||
306 | * |
||
307 | * @return KeyEncryptionAlgorithmInterface |
||
308 | */ |
||
309 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithmInterface |
||
318 | |||
319 | /** |
||
320 | * @param array $complete_headers |
||
321 | * |
||
322 | * @return ContentEncryptionAlgorithmInterface |
||
323 | */ |
||
324 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithmInterface |
||
333 | } |
||
334 |
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: