Skip to content

Commit 9cc4ac8

Browse files
Michael J Grubergitster
authored andcommitted
gpg_interface: allow to request status return
Currently, verify_signed_buffer() returns the user facing output only. Allow callers to request the status output also. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1315093 commit 9cc4ac8

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

builtin/fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
492492

493493
if (size == len)
494494
; /* merely annotated */
495-
else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig)) {
495+
else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig, NULL)) {
496496
if (!sig.len)
497497
strbuf_addstr(&sig, "gpg verification failed.\n");
498498
}

builtin/verify-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
2929
if (size == len)
3030
return error("no signature found");
3131

32-
return verify_signed_buffer(buf, len, buf + len, size - len, NULL);
32+
return verify_signed_buffer(buf, len, buf + len, size - len, NULL, NULL);
3333
}
3434

3535
static int verify_tag(const char *name, int verbose)

gpg-interface.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
100100
*/
101101
int verify_signed_buffer(const char *payload, size_t payload_size,
102102
const char *signature, size_t signature_size,
103-
struct strbuf *gpg_output)
103+
struct strbuf *gpg_output, struct strbuf *gpg_status)
104104
{
105105
struct child_process gpg;
106106
const char *args_gpg[] = {NULL, "--status-fd=1", "--verify", "FILE", "-", NULL};
107107
char path[PATH_MAX];
108108
int fd, ret;
109109
struct strbuf buf = STRBUF_INIT;
110+
struct strbuf *pbuf = &buf;
110111

111112
args_gpg[0] = gpg_program;
112113
fd = git_mkstemp(path, PATH_MAX, ".git_vtag_tmpXXXXXX");
@@ -137,15 +138,17 @@ int verify_signed_buffer(const char *payload, size_t payload_size,
137138
strbuf_read(gpg_output, gpg.err, 0);
138139
close(gpg.err);
139140
}
140-
strbuf_read(&buf, gpg.out, 0);
141+
if (gpg_status)
142+
pbuf = gpg_status;
143+
strbuf_read(pbuf, gpg.out, 0);
141144
close(gpg.out);
142145

143146
ret = finish_command(&gpg);
144147

145148
unlink_or_warn(path);
146149

147-
ret |= !strstr(buf.buf, "\n[GNUPG:] GOODSIG ");
148-
strbuf_release(&buf);
150+
ret |= !strstr(pbuf->buf, "\n[GNUPG:] GOODSIG ");
151+
strbuf_release(&buf); /* no matter it was used or not */
149152

150153
return ret;
151154
}

gpg-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define GPG_INTERFACE_H
33

44
extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
5-
extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output);
5+
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);
66
extern int git_gpg_config(const char *, const char *, void *);
77
extern void set_signing_key(const char *);
88
extern const char *get_signing_key(void);

log-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit)
434434

435435
status = verify_signed_buffer(payload.buf, payload.len,
436436
signature.buf, signature.len,
437-
&gpg_output);
437+
&gpg_output, NULL);
438438
if (status && !gpg_output.len)
439439
strbuf_addstr(&gpg_output, "No signature\n");
440440

@@ -503,7 +503,7 @@ static void show_one_mergetag(struct rev_info *opt,
503503
if (verify_signed_buffer(extra->value, payload_size,
504504
extra->value + payload_size,
505505
extra->len - payload_size,
506-
&verify_message)) {
506+
&verify_message, NULL)) {
507507
if (verify_message.len <= gpg_message_offset)
508508
strbuf_addstr(&verify_message, "No signature\n");
509509
else

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ static void parse_commit_signature(struct format_commit_context *ctx)
917917
goto out;
918918
status = verify_signed_buffer(payload.buf, payload.len,
919919
signature.buf, signature.len,
920-
&gpg_output);
920+
&gpg_output, NULL);
921921
if (status && !gpg_output.len)
922922
goto out;
923923
ctx->signature.gpg_output = strbuf_detach(&gpg_output, NULL);

0 commit comments

Comments
 (0)