Sanitize python object -> tag number exception handling
[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 signature(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 signature(s) to add
52  * @param passPhrase    private key pass phrase
53  * @return              0 on success, -1 on failure
54  */
55 int rpmAddSignature(Header sigh, const char * file,
56                     rpmSigTag sigTag, const char * passPhrase);
57
58 /** \ingroup signature
59  * Verify a signature from a package.
60  *
61  * @param keyring       keyring handle
62  * @param sigtd         signature tag data container
63  * @param dig           signature/pubkey parameters
64  * @retval result       detailed text result of signature verification
65  *                      (malloc'd)
66  * @return              result of signature verification
67  */
68 rpmRC rpmVerifySignature(rpmKeyring keyring, rpmtd sigtd, pgpDig dig, DIGEST_CTX ctx, char ** result);
69
70 /** \ingroup signature
71  * Destroy signature header from package.
72  * @param h             signature header
73  * @return              NULL always
74  */
75 Header rpmFreeSignature(Header h);
76
77 /******************************************************************/
78
79 /**
80  *  Possible actions for rpmLookupSignatureType()
81  */
82 #define RPMLOOKUPSIG_QUERY      0       /* Lookup type in effect          */
83 #define RPMLOOKUPSIG_DISABLE    1       /* Disable (--sign was not given) */
84 #define RPMLOOKUPSIG_ENABLE     2       /* Re-enable %_signature          */
85
86 /** \ingroup signature
87  * Return type of signature needed for signing/building.
88  * @param action        enable/disable/query action
89  * @return              sigTag to use, 0 if none, -1 on error
90  */
91 int rpmLookupSignatureType(int action);
92
93 /** \ingroup signature
94  * Read a pass phrase using getpass(3), confirm with gpg/pgp helper binaries.
95  * @param prompt        user prompt
96  * @param sigTag        signature type/tag
97  * @return              pass phrase
98  */
99 char * rpmGetPassPhrase(const char * prompt, const rpmSigTag sigTag);
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif  /* H_SIGNATURE */