1 | <?php |
||
17 | final class Encrypter implements EncrypterInterface |
||
18 | { |
||
19 | use Behaviour\HasKeyChecker; |
||
20 | use Behaviour\HasJWAManager; |
||
21 | use Behaviour\HasCompressionManager; |
||
22 | use Behaviour\CommonCipheringMethods; |
||
23 | use Behaviour\EncrypterTrait; |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public static function createEncrypter(array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF', 'ZLIB', 'GZ']) |
||
34 | |||
35 | /** |
||
36 | * Decrypter constructor. |
||
37 | * |
||
38 | * @param string[]|\Jose\Algorithm\KeyEncryptionAlgorithmInterface[] $key_encryption_algorithms |
||
39 | * @param string[]|\Jose\Algorithm\ContentEncryptionAlgorithmInterface[] $content_encryption_algorithms |
||
40 | * @param string[]|\Jose\Compression\CompressionInterface[] $compression_methods |
||
41 | */ |
||
42 | public function __construct(array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods) |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function encrypt(Object\JWEInterface &$jwe) |
||
78 | |||
79 | /** |
||
80 | * @param \Jose\Object\JWEInterface $jwe |
||
81 | * @param \Jose\Object\RecipientInterface $recipient |
||
82 | * @param string $cek |
||
83 | * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
84 | * @param array $additional_headers |
||
85 | */ |
||
86 | private function processRecipient(Object\JWEInterface $jwe, Object\RecipientInterface &$recipient, $cek, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers) |
||
103 | |||
104 | /** |
||
105 | * @param \Jose\Object\JWEInterface $jwe |
||
106 | * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
107 | * @param string $cek |
||
108 | * @param string $iv |
||
109 | * @param \Jose\Compression\CompressionInterface|null $compression_method |
||
110 | */ |
||
111 | private function encryptJWE(Object\JWEInterface &$jwe, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, $cek, $iv, Compression\CompressionInterface $compression_method = null) |
||
128 | |||
129 | /** |
||
130 | * @param string $payload |
||
131 | * @param \Jose\Compression\CompressionInterface|null $compression_method |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | private function preparePayload($payload, Compression\CompressionInterface $compression_method = null) |
||
148 | |||
149 | /** |
||
150 | * @param array $complete_headers |
||
151 | * @param string $cek |
||
152 | * @param \Jose\Algorithm\KeyEncryptionAlgorithmInterface $key_encryption_algorithm |
||
153 | * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
154 | * @param \Jose\Object\JWKInterface $recipient_key |
||
155 | * @param array $additional_headers |
||
156 | * |
||
157 | * @return string|null |
||
158 | */ |
||
159 | private function getEncryptedKey(array $complete_headers, $cek, Algorithm\KeyEncryptionAlgorithmInterface $key_encryption_algorithm, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers, Object\JWKInterface $recipient_key) |
||
169 | |||
170 | /** |
||
171 | * @param array $complete_headers |
||
172 | * @param string $cek |
||
173 | * @param \Jose\Algorithm\KeyEncryption\KeyAgreementWrappingInterface $key_encryption_algorithm |
||
174 | * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm |
||
175 | * @param array $additional_headers |
||
176 | * @param \Jose\Object\JWKInterface $recipient_key |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | private function getEncryptedKeyFromKeyAgreementAndKeyWrappingAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyAgreementWrappingInterface $key_encryption_algorithm, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers, Object\JWKInterface $recipient_key) |
||
186 | |||
187 | /** |
||
188 | * @param array $complete_headers |
||
189 | * @param string $cek |
||
190 | * @param \Jose\Algorithm\KeyEncryption\KeyEncryptionInterface $key_encryption_algorithm |
||
191 | * @param \Jose\Object\JWKInterface $recipient_key |
||
192 | * @param array $additional_headers |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | private function getEncryptedKeyFromKeyEncryptionAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyEncryptionInterface $key_encryption_algorithm, Object\JWKInterface $recipient_key, array &$additional_headers) |
||
200 | |||
201 | /** |
||
202 | * @param array $complete_headers |
||
203 | * @param string $cek |
||
204 | * @param \Jose\Algorithm\KeyEncryption\KeyWrappingInterface $key_encryption_algorithm |
||
205 | * @param \Jose\Object\JWKInterface $recipient_key |
||
206 | * @param array $additional_headers |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | private function getEncryptedKeyFromKeyWrappingAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyWrappingInterface $key_encryption_algorithm, Object\JWKInterface $recipient_key, &$additional_headers) |
||
214 | |||
215 | /** |
||
216 | * @param array $complete_headers |
||
217 | * |
||
218 | * @return \Jose\Algorithm\KeyEncryptionAlgorithmInterface |
||
219 | */ |
||
220 | private function findKeyEncryptionAlgorithm(array $complete_headers) |
||
228 | } |
||
229 |
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: