gpg-interface: move parse_gpg_output() to where it should be
Earlier, ffb6d7d5 (Move commit GPG signature verification to commit.c, 2013-03-31) moved this helper that used to be in pretty.c (i.e. the output code path) to commit.c for better reusability. It was a good first step in the right direction, but still suffers from a myopic view that commits will be the only thing we would ever want to sign---we would actually want to be able to reuse it even wider. The function interprets what GPG said; gpg-interface is obviously a better place. Move it there. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 14, 2014 at 15:31 UTC
a50e7ca3215492b16d96221cf762dbe71ed99722
3 files changed
+47
-41
commit.c
-36
@@ -1220,42 +1220,6 @@ free_return:
1220
free(buf);
1221
}
1222
1223
-static struct {
1224
- char result;
1225
- const char *check;
1226
-} sigcheck_gpg_status[] = {
1227
- { 'G', "\n[GNUPG:] GOODSIG " },
1228
- { 'B', "\n[GNUPG:] BADSIG " },
1229
- { 'U', "\n[GNUPG:] TRUST_NEVER" },
1230
- { 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
1231
-};
1232
-
1233
-static void parse_gpg_output(struct signature_check *sigc)
1234
-{
1235
- const char *buf = sigc->gpg_status;
1236
- int i;
1237
-
1238
- /* Iterate over all search strings */
1239
- for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
1240
- const char *found, *next;
1241
-
1242
- if (!skip_prefix(buf, sigcheck_gpg_status[i].check + 1, &found)) {
1243
- found = strstr(buf, sigcheck_gpg_status[i].check);
1244
- if (!found)
1245
- continue;
1246
- found += strlen(sigcheck_gpg_status[i].check);
1247
- }
1248
- sigc->result = sigcheck_gpg_status[i].result;
1249
- /* The trust messages are not followed by key/signer information */
1250
- if (sigc->result != 'U') {
1251
- sigc->key = xmemdupz(found, 16);
1252
- found += 17;
1253
- next = strchrnul(found, '\n');
1254
- sigc->signer = xmemdupz(found, next - found);
1255
- }
1256
- }
1257
-}
1258
-
1223
void check_commit_signature(const struct commit* commit, struct signature_check *sigc)
1224
{
1225
struct strbuf payload = STRBUF_INIT;
gpg-interface.c
+36
@@ -21,6 +21,42 @@ void signature_check_clear(struct signature_check *sigc)
21
sigc->key = NULL;
22
}
23
24
+static struct {
25
+ char result;
26
+ const char *check;
27
+} sigcheck_gpg_status[] = {
28
+ { 'G', "\n[GNUPG:] GOODSIG " },
29
+ { 'B', "\n[GNUPG:] BADSIG " },
30
+ { 'U', "\n[GNUPG:] TRUST_NEVER" },
31
+ { 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
32
+};
33
+
34
+void parse_gpg_output(struct signature_check *sigc)
35
+{
36
+ const char *buf = sigc->gpg_status;
37
+ int i;
38
+
39
+ /* Iterate over all search strings */
40
+ for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
41
+ const char *found, *next;
42
+
43
+ if (!skip_prefix(buf, sigcheck_gpg_status[i].check + 1, &found)) {
44
+ found = strstr(buf, sigcheck_gpg_status[i].check);
45
+ if (!found)
46
+ continue;
47
+ found += strlen(sigcheck_gpg_status[i].check);
48
+ }
49
+ sigc->result = sigcheck_gpg_status[i].result;
50
+ /* The trust messages are not followed by key/signer information */
51
+ if (sigc->result != 'U') {
52
+ sigc->key = xmemdupz(found, 16);
53
+ found += 17;
54
+ next = strchrnul(found, '\n');
55
+ sigc->signer = xmemdupz(found, next - found);
56
+ }
57
+ }
58
+}
59
+
60
void set_signing_key(const char *key)
61
{
62
free(configured_signing_key);
gpg-interface.h
+11
-5
@@ -5,16 +5,22 @@ struct signature_check {
5
char *payload;
6
char *gpg_output;
7
char *gpg_status;
8
- char result; /* 0 (not checked),
9
- * N (checked but no further result),
10
- * U (untrusted good),
11
- * G (good)
12
- * B (bad) */
8
+
9
+ /*
10
+ * possible "result":
11
+ * 0 (not checked)
12
+ * N (checked but no further result)
13
+ * U (untrusted good)
14
+ * G (good)
15
+ * B (bad)
16
+ */
17
+ char result;
18
char *signer;
19
char *key;
20
};
21
22
extern void signature_check_clear(struct signature_check *sigc);
23
+extern void parse_gpg_output(struct signature_check *);
24
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
25
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
26
extern int git_gpg_config(const char *, const char *, void *);