1 | <?php |
||
30 | final class Loader implements LoaderInterface |
||
31 | { |
||
32 | use HasLogger; |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function loadAndDecryptUsingKey($input, JWKInterface $jwk, array $allowed_key_encryption_algorithms, array $allowed_content_encryption_algorithms, &$recipient_index = null, LoggerInterface $logger = null) |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function loadAndDecryptUsingKeySet($input, JWKSetInterface $jwk_set, array $allowed_key_encryption_algorithms, array $allowed_content_encryption_algorithms, &$recipient_index = null, LoggerInterface $logger = null) |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function loadAndVerifySignatureUsingKey($input, JWKInterface $jwk, array $allowed_algorithms, &$signature_index = null, LoggerInterface $logger = null) |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function loadAndVerifySignatureUsingKeySet($input, JWKSetInterface $jwk_set, array $allowed_algorithms, &$signature_index = null, LoggerInterface $logger = null) |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function loadAndVerifySignatureUsingKeyAndDetachedPayload($input, JWKInterface $jwk, array $allowed_algorithms, $detached_payload, &$signature_index = null, LoggerInterface $logger = null) |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function loadAndVerifySignatureUsingKeySetAndDetachedPayload($input, JWKSetInterface $jwk_set, array $allowed_algorithms, $detached_payload, &$signature_index = null, LoggerInterface $logger = null) |
||
90 | |||
91 | /** |
||
92 | * @param string $input |
||
93 | * @param \Jose\Object\JWKSetInterface $jwk_set |
||
94 | * @param array $allowed_key_encryption_algorithms |
||
95 | * @param array $allowed_content_encryption_algorithms |
||
96 | * @param null|int $recipient_index |
||
97 | * @param \Psr\Log\LoggerInterface|null $logger |
||
98 | * |
||
99 | * @return \Jose\Object\JWEInterface |
||
100 | */ |
||
101 | private function loadAndDecrypt($input, JWKSetInterface $jwk_set, array $allowed_key_encryption_algorithms, array $allowed_content_encryption_algorithms, &$recipient_index = null, LoggerInterface $logger = null) |
||
111 | |||
112 | /** |
||
113 | * @param string $input |
||
114 | * @param \Jose\Object\JWKSetInterface $jwk_set |
||
115 | * @param array $allowed_algorithms |
||
116 | * @param string|null $detached_payload |
||
117 | * @param null|int $signature_index |
||
118 | * @param \Psr\Log\LoggerInterface|null $logger |
||
119 | * |
||
120 | * @return \Jose\Object\JWSInterface |
||
121 | */ |
||
122 | private function loadAndVerifySignature($input, JWKSetInterface $jwk_set, array $allowed_algorithms, $detached_payload = null, &$signature_index = null, LoggerInterface $logger = null) |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public function load($input) |
||
137 | { |
||
138 | $this->log(LogLevel::INFO, 'Trying to load the input.', ['input' => $input]); |
||
139 | $json = $this->convert($input); |
||
140 | if (array_key_exists('signatures', $json)) { |
||
141 | $this->log(LogLevel::DEBUG, 'The input is a JWS.', ['json' => $json]); |
||
142 | |||
143 | return JWSLoader::loadSerializedJsonJWS($json); |
||
144 | } |
||
145 | if (array_key_exists('recipients', $json)) { |
||
146 | $this->log(LogLevel::DEBUG, 'The input is a JWE.', ['json' => $json]); |
||
147 | |||
148 | return JWELoader::loadSerializedJsonJWE($json); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param string $input |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | private function convert($input) |
||
181 | |||
182 | /** |
||
183 | * @param $input |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | private function fromFlattenedSerializationRecipientToSerialization($input) |
||
209 | |||
210 | /** |
||
211 | * @param $input |
||
212 | * |
||
213 | * @return array |
||
214 | */ |
||
215 | private function fromFlattenedSerializationSignatureToSerialization($input) |
||
236 | |||
237 | /** |
||
238 | * @param string $input |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | private function fromCompactSerializationToSerialization($input) |
||
258 | |||
259 | /** |
||
260 | * @param array $parts |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | private function fromCompactSerializationRecipientToSerialization(array $parts) |
||
284 | |||
285 | /** |
||
286 | * @param array $parts |
||
287 | * |
||
288 | * @return array |
||
289 | */ |
||
290 | private function fromCompactSerializationSignatureToSerialization(array $parts) |
||
306 | } |
||
307 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.