1 | <?php |
||
35 | final class JWELoader |
||
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 | * JWELoader 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 | * @param string $input |
||
75 | * |
||
76 | * @return JWE |
||
77 | */ |
||
78 | public function load(string $input): JWE |
||
82 | |||
83 | /** |
||
84 | * @return string[] |
||
85 | */ |
||
86 | public function getSupportedCompressionMethods(): array |
||
90 | |||
91 | /** |
||
92 | * @return string[] |
||
93 | */ |
||
94 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
98 | |||
99 | /** |
||
100 | * @return string[] |
||
101 | */ |
||
102 | public function getSupportedContentEncryptionAlgorithms(): array |
||
106 | |||
107 | /** |
||
108 | * @param JWE $jwe A JWE object to decrypt |
||
109 | * @param JWK $jwk The key used to decrypt the input |
||
110 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
111 | * |
||
112 | * @return JWE |
||
113 | */ |
||
114 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
123 | |||
124 | /** |
||
125 | * @param JWE $jwe A JWE object to decrypt |
||
126 | * @param JWKSet $jwkset The key set used to decrypt the input |
||
127 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
128 | * |
||
129 | * @return JWE |
||
130 | */ |
||
131 | public function decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
150 | |||
151 | /** |
||
152 | * @param JWE $jwe |
||
153 | * @param JWKSet $jwkset |
||
154 | * @param int $i |
||
155 | * |
||
156 | * @return string|null |
||
157 | */ |
||
158 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
187 | |||
188 | /** |
||
189 | * @param JWE $jwe |
||
190 | */ |
||
191 | private function checkRecipients(JWE $jwe) |
||
197 | |||
198 | /** |
||
199 | * @param JWE $jwe |
||
200 | */ |
||
201 | private function checkPayload(JWE $jwe) |
||
207 | |||
208 | /** |
||
209 | * @param JWKSet $jwkset |
||
210 | */ |
||
211 | private function checkJWKSet(JWKSet $jwkset) |
||
217 | |||
218 | /** |
||
219 | * @param AlgorithmInterface $key_encryption_algorithm |
||
220 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
221 | * @param JWK $key |
||
222 | * @param Recipient $recipient |
||
223 | * @param array $complete_headers |
||
224 | * |
||
225 | * @return null|string |
||
226 | */ |
||
227 | private function decryptCEK(AlgorithmInterface $key_encryption_algorithm, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
243 | |||
244 | /** |
||
245 | * @param JWE $jwe |
||
246 | * @param string $cek |
||
247 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
248 | * @param array $complete_headers |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array $complete_headers): string |
||
261 | |||
262 | /** |
||
263 | * @param string $payload |
||
264 | * @param array $complete_headers |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
280 | |||
281 | /** |
||
282 | * @param array $complete_headers |
||
283 | * |
||
284 | * @throws \InvalidArgumentException |
||
285 | */ |
||
286 | private function checkCompleteHeader(array $complete_headers) |
||
294 | |||
295 | /** |
||
296 | * @param array $complete_headers |
||
297 | * |
||
298 | * @return KeyEncryptionAlgorithmInterface |
||
299 | */ |
||
300 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithmInterface |
||
309 | |||
310 | /** |
||
311 | * @param array $complete_headers |
||
312 | * |
||
313 | * @return ContentEncryptionAlgorithmInterface |
||
314 | */ |
||
315 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithmInterface |
||
324 | } |
||
325 |
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: