+ /*}}}*/
+bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile) /*{{{*/
+{
+ char * const message = GenerateTemporaryFileTemplate("fileutl.message");
+ int const messageFd = mkstemp(message);
+ if (messageFd == -1)
+ {
+ free(message);
+ return _error->Errno("mkstemp", "Couldn't create temporary file to work with %s", ClearSignedFileName.c_str());
+ }
+ // we have the fd, thats enough for us
+ unlink(message);
+ free(message);
+
+ int const duppedMsg = dup(messageFd);
+ if (duppedMsg == -1)
+ return _error->Errno("dup", "Couldn't duplicate FD to work with %s", ClearSignedFileName.c_str());
+
+ _error->PushToStack();
+ bool const splitDone = SplitClearSignedFile(ClearSignedFileName.c_str(), messageFd, NULL, -1);
+ bool const errorDone = _error->PendingError();
+ _error->MergeWithStack();
+ if (splitDone == false)
+ {
+ close(duppedMsg);
+
+ if (errorDone == true)
+ return false;
+
+ // we deal with an unsigned file
+ MessageFile.Open(ClearSignedFileName, FileFd::ReadOnly);
+ }
+ else // clear-signed
+ {
+ if (lseek(duppedMsg, 0, SEEK_SET) < 0)
+ return _error->Errno("lseek", "Unable to seek back in message fd for file %s", ClearSignedFileName.c_str());
+ MessageFile.OpenDescriptor(duppedMsg, FileFd::ReadOnly, true);
+ }
+
+ return MessageFile.Failed() == false;
+}
+ /*}}}*/