18bbdc7099d84f7c8d0c617b88bbabea7ca93662
[platform/upstream/rpm.git] / lib / signature.h
1 #ifndef H_SIGNATURE
2 #define H_SIGNATURE
3
4 /** \ingroup signature
5  * \file lib/signature.h
6  * Generate and verify signatures.
7  */
8
9 #include <rpm/header.h>
10
11 /** \ingroup signature
12  * Signature types stored in rpm lead.
13  */
14 typedef enum sigType_e {
15     RPMSIGTYPE_HEADERSIG= 5     /*!< Header style signature */
16 } sigType;
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /** \ingroup signature
23  * Return new, empty (signature) header instance.
24  * @return              signature header
25  */
26 Header rpmNewSignature(void);
27
28 /** \ingroup signature
29  * Read (and verify header+payload size) signature header.
30  * If an old-style signature is found, we emulate a new style one.
31  * @param fd            file handle
32  * @retval sighp        address of (signature) header (or NULL)
33  * @param sig_type      type of signature header to read (from lead)
34  * @retval msg          failure msg
35  * @return              rpmRC return code
36  */
37 rpmRC rpmReadSignature(FD_t fd, Header *sighp, sigType sig_type, char ** msg);
38
39 /** \ingroup signature
40  * Write signature header.
41  * @param fd            file handle
42  * @param h             (signature) header
43  * @return              0 on success, 1 on error
44  */
45 int rpmWriteSignature(FD_t fd, Header h);
46
47 /** \ingroup signature
48  * Generate digest(s) from a header+payload file, save in signature header.
49  * @param sigh          signature header
50  * @param file          header+payload file name
51  * @param sigTag        type of digest(s) to add
52  * @return              0 on success, -1 on failure
53  */
54 int rpmGenDigest(Header sigh, const char * file, rpmTagVal sigTag);
55
56 /** \ingroup signature
57  * Verify a signature from a package.
58  *
59  * @param keyring       keyring handle
60  * @param sigtd         signature tag data container
61  * @param sig           signature/pubkey parameters
62  * @retval result       detailed text result of signature verification
63  *                      (malloc'd)
64  * @return              result of signature verification
65  */
66 rpmRC rpmVerifySignature(rpmKeyring keyring, rpmtd sigtd, pgpDigParams sig,
67                          DIGEST_CTX ctx, char ** result);
68
69 /** \ingroup signature
70  * Destroy signature header from package.
71  * @param h             signature header
72  * @return              NULL always
73  */
74 Header rpmFreeSignature(Header h);
75
76 /* Dumb wrapper around pgpPrtParams() to log some error messages on failure */
77 RPM_GNUC_INTERNAL
78 int parsePGPSig(rpmtd sigtd, const char *type, const char *fn,
79                  pgpDigParams *sig);
80
81 #ifdef __cplusplus
82 }
83 #endif
84
85 #endif  /* H_SIGNATURE */