countRecipients() public method

Returns the number of recipients associated with the JWS.
public countRecipients ( ) : integer
return integer
Beispiel #1
0
 /**
  * @param \Jose\Object\JWEInterface                           $jwe
  * @param \Jose\Object\RecipientInterface                     $recipient
  * @param string                                              $cek
  * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm
  * @param array                                               $additional_headers
  */
 private function processRecipient(Object\JWEInterface $jwe, Object\RecipientInterface &$recipient, $cek, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers)
 {
     if (null === $recipient->getRecipientKey()) {
         return;
     }
     $complete_headers = array_merge($jwe->getSharedProtectedHeaders(), $jwe->getSharedHeaders(), $recipient->getHeaders());
     $key_encryption_algorithm = $this->findKeyEncryptionAlgorithm($complete_headers);
     $this->checkKeys($key_encryption_algorithm, $content_encryption_algorithm, $recipient->getRecipientKey());
     $encrypted_content_encryption_key = $this->getEncryptedKey($complete_headers, $cek, $key_encryption_algorithm, $content_encryption_algorithm, $additional_headers, $recipient->getRecipientKey());
     $recipient_headers = $recipient->getHeaders();
     if (!empty($additional_headers) && 1 !== $jwe->countRecipients()) {
         $recipient_headers = array_merge($recipient_headers, $additional_headers);
         $additional_headers = [];
     }
     $recipient = Object\Recipient::createRecipientFromLoadedJWE($recipient_headers, $encrypted_content_encryption_key);
 }
Beispiel #2
0
 /**
  * @param \Jose\Object\JWEInterface $jwe
  *
  * @return \Jose\Compression\CompressionInterface|null
  */
 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;
 }
Beispiel #3
0
 /**
  * @param \Jose\Object\JWEInterface $jwe
  */
 private function checkRecipients(Object\JWEInterface $jwe)
 {
     Assertion::greaterThan($jwe->countRecipients(), 0, 'The JWE does not contain any recipient.');
 }