Sync with 2.25.5
[git] / gpg-interface.h
1 #ifndef GPG_INTERFACE_H
2 #define GPG_INTERFACE_H
3
4 struct strbuf;
5
6 #define GPG_VERIFY_VERBOSE              1
7 #define GPG_VERIFY_RAW                  2
8 #define GPG_VERIFY_OMIT_STATUS  4
9
10 enum signature_trust_level {
11         TRUST_UNDEFINED,
12         TRUST_NEVER,
13         TRUST_MARGINAL,
14         TRUST_FULLY,
15         TRUST_ULTIMATE,
16 };
17
18 struct signature_check {
19         char *payload;
20         char *gpg_output;
21         char *gpg_status;
22
23         /*
24          * possible "result":
25          * 0 (not checked)
26          * N (checked but no further result)
27          * G (good)
28          * B (bad)
29          */
30         char result;
31         char *signer;
32         char *key;
33         char *fingerprint;
34         char *primary_key_fingerprint;
35         enum signature_trust_level trust_level;
36 };
37
38 void signature_check_clear(struct signature_check *sigc);
39
40 /*
41  * Look at GPG signed content (e.g. a signed tag object), whose
42  * payload is followed by a detached signature on it.  Return the
43  * offset where the embedded detached signature begins, or the end of
44  * the data when there is no such signature.
45  */
46 size_t parse_signature(const char *buf, size_t size);
47
48 /*
49  * Create a detached signature for the contents of "buffer" and append
50  * it after "signature"; "buffer" and "signature" can be the same
51  * strbuf instance, which would cause the detached signature appended
52  * at the end.
53  */
54 int sign_buffer(struct strbuf *buffer, struct strbuf *signature,
55                 const char *signing_key);
56
57 /*
58  * Run "gpg" to see if the payload matches the detached signature.
59  * gpg_output, when set, receives the diagnostic output from GPG.
60  * gpg_status, when set, receives the status output from GPG.
61  */
62 int verify_signed_buffer(const char *payload, size_t payload_size,
63                          const char *signature, size_t signature_size,
64                          struct strbuf *gpg_output, struct strbuf *gpg_status);
65
66 int git_gpg_config(const char *, const char *, void *);
67 void set_signing_key(const char *);
68 const char *get_signing_key(void);
69 int check_signature(const char *payload, size_t plen,
70                     const char *signature, size_t slen,
71                     struct signature_check *sigc);
72 void print_signature_buffer(const struct signature_check *sigc,
73                             unsigned flags);
74
75 #endif