/**
  * Timestamps a collection of document instances.
  *
  * The document instances need to have writer instances setup properbly.
  *
  * @param SetaPDF_Core_Document[] $documents
  * @param bool $updateDss
  * @return bool
  * @throws SetaPDF_Core_Exception
  * @throws SetaPDF_Signer_Exception
  * @throws SetaPDF_Signer_Exception_ContentLength
  * @throws SetaPDF_Signer_SwisscomAIS_Exception
  */
 public function timestamp(array $documents, $updateDss = false)
 {
     $digestMethod = $this->_getDigestMethod();
     $data = array();
     $no = 0;
     foreach ($documents as $document) {
         $signer = new SetaPDF_Signer($document);
         $signer->setSignatureContentLength($this->getSignatureContentLength());
         $signer->setSignatureFieldName($this->getSignatureFieldName());
         $tmpDocument = $signer->preTimestamp(new SetaPDF_Core_Writer_TempFile());
         $data[$no] = array('document' => $document, 'signer' => $signer, 'tmpDocument' => $tmpDocument, 'digestValue' => $this->_getHash($tmpDocument->getHashFile()));
         $no++;
     }
     $req = array('SignRequest' => array('RequestID' => $this->_createRequestId(), 'Profile' => 'http://ais.swisscom.ch/1.0', 'OptionalInputs' => array('SignatureType' => 'urn:ietf:rfc:3161', 'ClaimedIdentity' => array('Name' => $this->_customerId), 'AdditionalProfile' => array('http://ais.swisscom.ch/1.0/profiles/batchprocessing', 'urn:oasis:names:tc:dss:1.0:profiles:timestamping')), 'InputDocuments' => array()));
     foreach ($data as $no => $documentData) {
         $req['SignRequest']['InputDocuments'][] = array('ID' => $no, 'DigestMethod' => array('Algorithm' => $digestMethod), 'DigestValue' => $documentData['digestValue']);
     }
     if ($this->_revokeInformation) {
         $req['SignRequest']['OptionalInputs']['AddRevocationInformation'] = array('Type' => $this->_revokeInformation);
     }
     $client = new SoapClient($this->_wsdl, array_merge($this->_clientOptions, array('trace' => true, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_1)));
     $this->_lastResult = $client->sign($req);
     $signResult = $this->_lastResult->SignResponse->Result;
     if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {
         $exception = new SetaPDF_Signer_SwisscomAIS_Exception($signResult->ResultMessage->_);
         $exception->setRequest($req);
         $exception->setResult($this->_lastResult);
         throw $exception;
     }
     $timestamps = $this->_lastResult->SignResponse->SignatureObject->Other->SignatureObjects->ExtendedSignatureObject;
     if (!is_array($timestamps)) {
         $timestamps = array($timestamps);
     }
     foreach ($timestamps as $timestampData) {
         $timestamp = $timestampData->Timestamp->RFC3161TimeStampToken;
         $no = $timestampData->WhichDocument;
         $this->_signatures[$no] = $timestamp;
         $documentData = $data[$no];
         /**
          * @var $signer SetaPDF_Signer
          */
         $signer = $documentData['signer'];
         if (!$updateDss || !$this->_revokeInformation) {
             $signer->saveSignature($documentData['tmpDocument'], $timestamp);
         } else {
             $tempWriter = new SetaPDF_Core_Writer_TempFile();
             $writer = $documentData['document']->getWriter();
             $documentData['document']->setWriter($tempWriter);
             $signer->saveSignature($documentData['tmpDocument'], $timestamp);
             $document = SetaPDF_Core_Document::loadByFilename($tempWriter->getPath(), $writer);
             $this->updateDss($document, $this->getSignatureFieldName());
             $document->save()->finish();
         }
     }
     return true;
 }
 /**
  * Create the timestamp signature.
  *
  * @param string|SetaPDF_Core_Reader_FilePath $data
  * @return SetaPDF_Signer_Asn1_Element
  * @throws SetaPDF_Signer_Exception
  */
 public function createTimestamp($data)
 {
     $digestMethod = $this->_getDigestMethod();
     $digestValue = $this->_getHash($data);
     $req = array('SignRequest' => array('RequestID' => $this->_createRequestId(), 'Profile' => 'http://ais.swisscom.ch/1.0', 'OptionalInputs' => array('SignatureType' => 'urn:ietf:rfc:3161', 'AdditionalProfile' => array('urn:oasis:names:tc:dss:1.0:profiles:timestamping'), 'ClaimedIdentity' => array('Name' => $this->_customerId)), 'InputDocuments' => array('DocumentHash' => array('DigestMethod' => array('Algorithm' => $digestMethod), 'DigestValue' => $digestValue))));
     if ($this->_revokeInformation) {
         $req['SignRequest']['OptionalInputs']['AddRevocationInformation'] = array('Type' => $this->_revokeInformation);
     }
     $client = new SoapClient($this->_wsdl, array_merge($this->_clientOptions, array('trace' => true, 'encoding' => 'UTF-8', 'soap_version' => SOAP_1_1)));
     $this->_lastResult = $client->sign($req);
     $signResult = $this->_lastResult->SignResponse->Result;
     if ($signResult->ResultMajor !== 'urn:oasis:names:tc:dss:1.0:resultmajor:Success') {
         $exception = new SetaPDF_Signer_SwisscomAIS_Exception($signResult->ResultMessage->_);
         $exception->setRequest($req);
         $exception->setResult($this->_lastResult);
         throw $exception;
     }
     $this->_signature = $this->_lastResult->SignResponse->SignatureObject->Timestamp->RFC3161TimeStampToken;
     return $this->_signature;
 }