]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/gpgv.h
- if ExecGPGV deals with a clear-signed file it will split this file
[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 #if __GNUC__ >= 4
16 #define APT_noreturn __attribute__ ((noreturn))
17 #else
18 #define APT_noreturn /* no support */
19 #endif
20
21 /** \brief generates and run the command to verify a file with gpgv
22 *
23 * If File and FileSig specify the same file it is assumed that we
24 * deal with a clear-signed message. In that case the file will be
25 * rewritten to be in a good-known format without uneeded whitespaces
26 * and additional messages (unsigned or signed).
27 *
28 * @param File is the message (unsigned or clear-signed)
29 * @param FileSig is the signature (detached or clear-signed)
30 */
31 void ExecGPGV(std::string const &File, std::string const &FileSig,
32 int const &statusfd, int fd[2]) APT_noreturn;
33 inline void ExecGPGV(std::string const &File, std::string const &FileSig,
34 int const &statusfd = -1) {
35 int fd[2];
36 ExecGPGV(File, FileSig, statusfd, fd);
37 };
38
39 #undef APT_noreturn
40
41 /** \brief Split an inline signature into message and signature
42 *
43 * Takes a clear-signed message and puts the first signed message
44 * in the content file and all signatures following it into the
45 * second. Unsigned messages, additional messages as well as
46 * whitespaces are discarded. The resulting files are suitable to
47 * be checked with gpgv.
48 *
49 * If one or all Fds are -1 they will not be used and the content
50 * which would have been written to them is discarded.
51 *
52 * The code doesn't support dash-encoded lines as these are not
53 * expected to be present in files we have to deal with.
54 *
55 * @param InFile is the clear-signed file
56 * @param ContentFile is the Fd the message will be written to
57 * @param ContentHeader is a list of all required Amored Headers for the message
58 * @param SignatureFile is the Fd all signatures will be written to
59 */
60 bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
61 std::vector<std::string> * const ContentHeader, int const SignatureFile);
62
63 /** \brief recombines message and signature to an inline signature
64 *
65 * Reverses the splitting down by #SplitClearSignedFile by writing
66 * a well-formed clear-signed message without unsigned messages,
67 * additional signed messages or just trailing whitespaces
68 *
69 * @param OutFile will be clear-signed file
70 * @param ContentFile is the Fd the message will be read from
71 * @param ContentHeader is a list of all required Amored Headers for the message
72 * @param SignatureFile is the Fd all signatures will be read from
73 */
74 bool RecombineToClearSignedFile(std::string const &OutFile, int const ContentFile,
75 std::vector<std::string> const &ContentHeader, int const SignatureFile);
76
77 #endif