Skip to content

Commit a50e7ca

Browse files
committed
gpg-interface: move parse_gpg_output() to where it should be
Earlier, ffb6d7d (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 <[email protected]>
1 parent c67072b commit a50e7ca

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

commit.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,42 +1220,6 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
12201220
free(buf);
12211221
}
12221222

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-
12591223
void check_commit_signature(const struct commit* commit, struct signature_check *sigc)
12601224
{
12611225
struct strbuf payload = STRBUF_INIT;

gpg-interface.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@ void signature_check_clear(struct signature_check *sigc)
2121
sigc->key = NULL;
2222
}
2323

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+
2460
void set_signing_key(const char *key)
2561
{
2662
free(configured_signing_key);

gpg-interface.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ struct signature_check {
55
char *payload;
66
char *gpg_output;
77
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;
1318
char *signer;
1419
char *key;
1520
};
1621

1722
extern void signature_check_clear(struct signature_check *sigc);
23+
extern void parse_gpg_output(struct signature_check *);
1824
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
1925
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);
2026
extern int git_gpg_config(const char *, const char *, void *);

0 commit comments

Comments
 (0)