]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/gpgv.h
Merge remote-tracking branch 'donkult/debian/sid' into debian/sid
[apt.git] / apt-pkg / contrib / gpgv.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
5 Helpers to deal with gpgv better and more easily
6
7 ##################################################################### */
8 /*}}}*/
9 #ifndef CONTRIB_GPGV_H
10 #define CONTRIB_GPGV_H
11
12 #include <string>
13 #include <vector>
14
15 #include <apt-pkg/fileutl.h>
16
17 #if __GNUC__ >= 4
18 #define APT_noreturn __attribute__ ((noreturn))
19 #else
20 #define APT_noreturn /* no support */
21 #endif
22
23 /** \brief generates and run the command to verify a file with gpgv
24 *
25 * If File and FileSig specify the same file it is assumed that we
26 * deal with a clear-signed message. Note that the method will accept
27 * and validate files which include additional (unsigned) messages
28 * without complaining. Do NOT open files accepted by this method
29 * for reading. Use #OpenMaybeClearSignedFile to access the message
30 * instead to ensure you are only reading signed data.
31 *
32 * The method does not return, but has some noteable exit-codes:
33 * 111 signals an internal error like the inability to execute gpgv,
34 * 112 indicates a clear-signed file which doesn't include a message,
35 * which can happen if APT is run while on a network requiring
36 * authentication before usage (e.g. in hotels)
37 * All other exit-codes are passed-through from gpgv.
38 *
39 * @param File is the message (unsigned or clear-signed)
40 * @param FileSig is the signature (detached or clear-signed)
41 */
42 void ExecGPGV(std::string const &File, std::string const &FileSig,
43 int const &statusfd, int fd[2]) APT_noreturn;
44 inline void ExecGPGV(std::string const &File, std::string const &FileSig,
45 int const &statusfd = -1) {
46 int fd[2];
47 ExecGPGV(File, FileSig, statusfd, fd);
48 };
49
50 #undef APT_noreturn
51
52 /** \brief Split an inline signature into message and signature
53 *
54 * Takes a clear-signed message and puts the first signed message
55 * in the content file and all signatures following it into the
56 * second. Unsigned messages, additional messages as well as
57 * whitespaces are discarded. The resulting files are suitable to
58 * be checked with gpgv.
59 *
60 * If a FileFd pointers is NULL it will not be used and the content
61 * which would have been written to it is silently discarded.
62 *
63 * The content of the split files is undefined if the splitting was
64 * unsuccessful.
65 *
66 * Note that trying to split an unsigned file will fail, but
67 * not generate an error message.
68 *
69 * @param InFile is the clear-signed file
70 * @param ContentFile is the FileFd the message will be written to
71 * @param ContentHeader is a list of all required Amored Headers for the message
72 * @param SignatureFile is the FileFd all signatures will be written to
73 * @return true if the splitting was successful, false otherwise
74 */
75 bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile,
76 std::vector<std::string> * const ContentHeader, FileFd * const SignatureFile);
77
78 /** \brief open a file which might be clear-signed
79 *
80 * This method tries to extract the (signed) message of a file.
81 * If the file isn't signed it will just open the given filename.
82 * Otherwise the message is extracted to a temporary file which
83 * will be opened instead.
84 *
85 * @param ClearSignedFileName is the name of the file to open
86 * @param[out] MessageFile is the FileFd in which the file will be opened
87 * @return true if opening was successful, otherwise false
88 */
89 bool OpenMaybeClearSignedFile(std::string const &ClearSignedFileName, FileFd &MessageFile);
90
91 #endif