/**
  * Create the signature.
  *
  * @param SetaPDF_Core_Reader_FilePath|string $tmpPath
  * @return mixed
  * @throws SetaPDF_Signer_Exception
  */
 public function createSignature($tmpPath)
 {
     if (!file_exists($tmpPath) || !is_readable($tmpPath)) {
         throw new InvalidArgumentException('Signature template file cannot be read.');
     }
     $signaturType = 'urn:ietf:rfc:3369';
     $flags = 0x400;
     switch ($this->getDigest()) {
         case SetaPDF_Signer_Digest::SHA_1:
             $flags |= 0x100000;
             break;
         case SetaPDF_Signer_Digest::SHA_256:
             $flags |= 0x4000;
             break;
         case SetaPDF_Signer_Digest::SHA_384:
             $flags |= 0x8000;
             break;
         case SetaPDF_Signer_Digest::SHA_512:
             $flags |= 0x10000;
             break;
         default:
             throw new BadMethodCallException('The used digest method is not supported by the CoSign API.');
     }
     $req = array('SignRequest' => array('OptionalInputs' => array('ClaimedIdentity' => array('Name' => array('_' => $this->_username, 'NameQualifier' => $this->_domain), 'SupportingInfo' => array('LogonPassword' => $this->_password)), 'SignatureType' => $signaturType, 'Flags' => $flags, 'ConfigurationValues' => array('ConfValue' => array())), 'InputDocuments' => array('Document' => array('Base64Data' => array('_' => hash_file($this->getDigest(), $tmpPath, true), 'MimeType' => 'application/octet-string')))));
     if (isset($this->_timestampData)) {
         $confValue =& $req['SignRequest']['OptionalInputs']['ConfigurationValues']['ConfValue'];
         $confValue[] = array('ConfValueID' => 'UseTimestamp', 'IntegerValue' => 1);
         $confValue[] = array('ConfValueID' => 'TimestampURL', 'StringValue' => $this->_timestampData['url']);
         $confValue[] = array('ConfValueID' => 'TimestampUser', 'StringValue' => $this->_timestampData['username']);
         $confValue[] = array('ConfValueID' => 'TimestampPWD', 'StringValue' => $this->_timestampData['password']);
     }
     $client = new SoapClient($this->_wsdl, array_merge($this->_clientOptions, array('trace' => true)));
     $result = $client->DssSign($req);
     if ($result->DssSignResult->Result->ResultMajor != "urn:oasis:names:tc:dss:1.0:resultmajor:Success") {
         throw new SetaPDF_Signer_Exception(sprintf('CoSign webservice returned an error: %s', $result->DssSignResult->Result->ResultMessage->_));
     }
     return $result->DssSignResult->OptionalOutputs->DocumentWithSignature->Document->Base64Data->_;
 }