gpgv.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Helpers to deal with gpgv better and more easily
  5. ##################################################################### */
  6. /*}}}*/
  7. #ifndef CONTRIB_GPGV_H
  8. #define CONTRIB_GPGV_H
  9. #include <string>
  10. #include <vector>
  11. #include <apt-pkg/fileutl.h>
  12. #if __GNUC__ >= 4
  13. #define APT_noreturn __attribute__ ((noreturn))
  14. #else
  15. #define APT_noreturn /* no support */
  16. #endif
  17. /** \brief generates and run the command to verify a file with gpgv
  18. *
  19. * If File and FileSig specify the same file it is assumed that we
  20. * deal with a clear-signed message. In that case the file will be
  21. * rewritten to be in a good-known format without uneeded whitespaces
  22. * and additional messages (unsigned or signed).
  23. *
  24. * @param File is the message (unsigned or clear-signed)
  25. * @param FileSig is the signature (detached or clear-signed)
  26. */
  27. void ExecGPGV(std::string const &File, std::string const &FileSig,
  28. int const &statusfd, int fd[2]) APT_noreturn;
  29. inline void ExecGPGV(std::string const &File, std::string const &FileSig,
  30. int const &statusfd = -1) {
  31. int fd[2];
  32. ExecGPGV(File, FileSig, statusfd, fd);
  33. };
  34. #undef APT_noreturn
  35. /** \brief Split an inline signature into message and signature
  36. *
  37. * Takes a clear-signed message and puts the first signed message
  38. * in the content file and all signatures following it into the
  39. * second. Unsigned messages, additional messages as well as
  40. * whitespaces are discarded. The resulting files are suitable to
  41. * be checked with gpgv.
  42. *
  43. * If a FileFd pointers is NULL it will not be used and the content
  44. * which would have been written to it is silently discarded.
  45. *
  46. * The content of the split files is undefined if the splitting was
  47. * unsuccessful.
  48. *
  49. * Note that trying to split an unsigned file will fail, but
  50. * not generate an error message.
  51. *
  52. * @param InFile is the clear-signed file
  53. * @param ContentFile is the FileFd the message will be written to
  54. * @param ContentHeader is a list of all required Amored Headers for the message
  55. * @param SignatureFile is the FileFd all signatures will be written to
  56. * @return true if the splitting was successful, false otherwise
  57. */
  58. bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
  59. std::vector<std::string> * const ContentHeader, FileFd * const SignatureFile);
  60. /** \brief open a file which might be clear-signed
  61. *
  62. * This method tries to extract the (signed) message of a file.
  63. * If the file isn't signed it will just open the given filename.
  64. * Otherwise the message is extracted to a temporary file which
  65. * will be opened instead.
  66. *
  67. * @param ClearSignedFileName is the name of the file to open
  68. * @param[out] MessageFile is the FileFd in which the file will be opened
  69. * @return true if opening was successful, otherwise false
  70. */
  71. bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile);
  72. #endif