private function getCompressionMethod(Object\JWEInterface $jwe)
{
$method = null;
$nb_recipients = $jwe->countRecipients();
for ($i = 0; $i < $nb_recipients; $i++) {
$complete_headers = array_merge($jwe->getSharedProtectedHeaders(), $jwe->getSharedHeaders(), $jwe->getRecipient($i)->getHeaders());
if (array_key_exists('zip', $complete_headers)) {
if (null === $method) {
if (0 === $i) {
$method = $complete_headers['zip'];
} else {
throw new \InvalidArgumentException('Inconsistent "zip" parameter.');
}
} else {
Assertion::eq($method, $complete_headers['zip'], 'Inconsistent "zip" parameter.');
}
} else {
Assertion::eq(null, $method, 'Inconsistent "zip" parameter.');
}
}
if (null === $method) {
return;
}
$compression_method = $this->getCompressionManager()->getCompressionAlgorithm($method);
Assertion::isInstanceOf($compression_method, Compression\CompressionInterface::class, sprintf('Compression method "%s" not supported.', $method));
return $compression_method;
}