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 | * |
||
84 | * @return JWE |
||
85 | */ |
||
86 | public function load(string $input): JWE |
||
90 | |||
91 | /** |
||
92 | * @return AlgorithmManager |
||
93 | */ |
||
94 | public function getKeyEncryptionAlgorithmManager(): AlgorithmManager |
||
95 | { |
||
96 | return $this->keyEncryptionAlgorithmManager; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return AlgorithmManager |
||
101 | */ |
||
102 | public function getContentEncryptionAlgorithmManager(): AlgorithmManager |
||
103 | { |
||
104 | return $this->contentEncryptionAlgorithmManager; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return CompressionMethodManager |
||
109 | */ |
||
110 | public function getCompressionMethodManager(): CompressionMethodManager |
||
111 | { |
||
112 | return $this->compressionMethodManager; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @param JWE $jwe A JWE object to decrypt |
||
117 | * @param JWK $jwk The key used to decrypt the input |
||
118 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
119 | * |
||
120 | * @return JWE |
||
121 | */ |
||
122 | public function decryptUsingKey(JWE $jwe, JWK $jwk, ?int &$recipientIndex = null): JWE |
||
131 | |||
132 | /** |
||
133 | * @param JWE $jwe A JWE object to decrypt |
||
134 | * @param JWKSet $jwkset The key set used to decrypt the input |
||
135 | * @param null|int $recipientIndex If the JWE has been decrypted, an integer that represents the ID of the recipient is set |
||
136 | * |
||
137 | * @return JWE |
||
138 | */ |
||
139 | public function decryptUsingKeySet(JWE $jwe, JWKSet $jwkset, ?int &$recipientIndex = null): JWE |
||
158 | |||
159 | /** |
||
160 | * @param JWE $jwe |
||
161 | * @param JWKSet $jwkset |
||
162 | * @param int $i |
||
163 | * |
||
164 | * @return string|null |
||
165 | */ |
||
166 | private function decryptRecipientKey(JWE $jwe, JWKSet $jwkset, int $i): ?string |
||
195 | |||
196 | /** |
||
197 | * @param JWE $jwe |
||
198 | */ |
||
199 | private function checkRecipients(JWE $jwe) |
||
205 | |||
206 | /** |
||
207 | * @param JWE $jwe |
||
208 | */ |
||
209 | private function checkPayload(JWE $jwe) |
||
215 | |||
216 | /** |
||
217 | * @param JWKSet $jwkset |
||
218 | */ |
||
219 | private function checkJWKSet(JWKSet $jwkset) |
||
225 | |||
226 | /** |
||
227 | * @param AlgorithmInterface $key_encryption_algorithm |
||
228 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
229 | * @param JWK $key |
||
230 | * @param Recipient $recipient |
||
231 | * @param array $complete_headers |
||
232 | * |
||
233 | * @return null|string |
||
234 | */ |
||
235 | private function decryptCEK(AlgorithmInterface $key_encryption_algorithm, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, JWK $key, Recipient $recipient, array $complete_headers): ?string |
||
251 | |||
252 | /** |
||
253 | * @param JWE $jwe |
||
254 | * @param string $cek |
||
255 | * @param ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
256 | * @param array $complete_headers |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | private function decryptPayload(JWE $jwe, string $cek, ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array $complete_headers): string |
||
269 | |||
270 | /** |
||
271 | * @param string $payload |
||
272 | * @param array $complete_headers |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | private function decompressIfNeeded(string $payload, array $complete_headers): string |
||
288 | |||
289 | /** |
||
290 | * @param array $complete_headers |
||
291 | * |
||
292 | * @throws \InvalidArgumentException |
||
293 | */ |
||
294 | private function checkCompleteHeader(array $complete_headers) |
||
302 | |||
303 | /** |
||
304 | * @param array $complete_headers |
||
305 | * |
||
306 | * @return KeyEncryptionAlgorithmInterface |
||
307 | */ |
||
308 | private function getKeyEncryptionAlgorithm(array $complete_headers): KeyEncryptionAlgorithmInterface |
||
317 | |||
318 | /** |
||
319 | * @param array $complete_headers |
||
320 | * |
||
321 | * @return ContentEncryptionAlgorithmInterface |
||
322 | */ |
||
323 | private function getContentEncryptionAlgorithm(array $complete_headers): ContentEncryptionAlgorithmInterface |
||
332 | } |
||
333 |
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: