1 | <?php |
||
34 | final class JWEDecrypter |
||
35 | { |
||
36 | /** |
||
37 | * @var AlgorithmManager |
||
38 | */ |
||
39 | private $keyEncryptionAlgorithmManager; |
||
40 | |||
41 | /** |
||
42 | * @var AlgorithmManager |
||
43 | */ |
||
44 | private $contentEncryptionAlgorithmManager; |
||
45 | |||
46 | /** |
||
47 | * @var CompressionMethodManager |
||
48 | */ |
||
49 | private $compressionMethodManager; |
||
50 | |||
51 | /** |
||
52 | * JWEDecrypter constructor. |
||
53 | * |
||
54 | * @param AlgorithmManager $keyEncryptionAlgorithmManager |
||
55 | * @param AlgorithmManager $contentEncryptionAlgorithmManager |
||
56 | * @param CompressionMethodManager $compressionMethodManager |
||
57 | */ |
||
58 | public function __construct(AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionMethodManager) |
||
64 | |||
65 | /** |
||
66 | * @return AlgorithmManager |
||
67 | */ |
||
68 | public function getKeyEncryptionAlgorithmManager(): AlgorithmManager |
||
72 | |||
73 | /** |
||
74 | * @return AlgorithmManager |
||
75 | */ |
||
76 | public function getContentEncryptionAlgorithmManager(): AlgorithmManager |
||
80 | |||
81 | /** |
||
82 | * @return CompressionMethodManager |
||
83 | */ |
||
84 | public function getCompressionMethodManager(): CompressionMethodManager |
||
88 | |||
89 | /** |
||
90 | * @param JWE $jwe A JWE object to decrypt |
||
91 | * @param JWK $jwk The key used to decrypt the input |
||
92 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
93 | * |
||
94 | * @return JWE |
||
95 | */ |
||
96 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
103 | |||
104 | /** |
||
105 | * @param JWE $jwe A JWE object to decrypt |
||
106 | * @param JWKSet $jwkset The key set 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 decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
130 | |||
131 | /** |
||
132 | * @param JWE $jwe |
||
133 | * @param JWKSet $jwkset |
||
134 | * @param int $i |
||
135 | * |
||
136 | * @return string|null |
||
137 | */ |
||
138 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
167 | |||
168 | /** |
||
169 | * @param JWE $jwe |
||
170 | */ |
||
171 | private function checkRecipients(JWE $jwe) |
||
177 | |||
178 | /** |
||
179 | * @param JWE $jwe |
||
180 | */ |
||
181 | private function checkPayload(JWE $jwe) |
||
187 | |||
188 | /** |
||
189 | * @param JWKSet $jwkset |
||
190 | */ |
||
191 | private function checkJWKSet(JWKSet $jwkset) |
||
197 | |||
198 | /** |
||
199 | * @param Algorithm $key_encryption_algorithm |
||
200 | * @param ContentEncryptionAlgorithm $content_encryption_algorithm |
||
201 | * @param JWK $key |
||
202 | * @param Recipient $recipient |
||
203 | * @param array $complete_headers |
||
204 | * |
||
205 | * @return null|string |
||
206 | */ |
||
207 | private function decryptCEK(Algorithm $key_encryption_algorithm, ContentEncryptionAlgorithm $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
223 | |||
224 | /** |
||
225 | * @param JWE $jwe |
||
226 | * @param string $cek |
||
227 | * @param ContentEncryptionAlgorithm $content_encryption_algorithm |
||
228 | * @param array $complete_headers |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithm $content_encryption_algorithm, array $complete_headers): string |
||
241 | |||
242 | /** |
||
243 | * @param string $payload |
||
244 | * @param array $complete_headers |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
260 | |||
261 | /** |
||
262 | * @param array $complete_headers |
||
263 | * |
||
264 | * @throws \InvalidArgumentException |
||
265 | */ |
||
266 | private function checkCompleteHeader(array $complete_headers) |
||
274 | |||
275 | /** |
||
276 | * @param array $complete_headers |
||
277 | * |
||
278 | * @return KeyEncryptionAlgorithm |
||
279 | */ |
||
280 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithm |
||
289 | |||
290 | /** |
||
291 | * @param array $complete_headers |
||
292 | * |
||
293 | * @return ContentEncryptionAlgorithm |
||
294 | */ |
||
295 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithm |
||
304 | } |
||
305 |
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: