gpg: centralize printing signature buffers
The code to handle printing of signature data from a struct signature_check is very similar between verify-commit and verify-tag. Place this in a single function. verify-tag retains its special case behavior of printing the tag even when no valid signature is found. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jun 21, 2015 at 23:14 UTC
ca194d50b84b53a0b711fef46d1a47657ec5da41
4 files changed
+18
-10
builtin/verify-commit.c
+1
-6
@@ -26,12 +26,7 @@ static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned l
26
memset(&signature_check, 0, sizeof(signature_check));
27
28
ret = check_commit_signature(lookup_commit(sha1), &signature_check);
29
-
30
- if (verbose && signature_check.payload)
31
- fputs(signature_check.payload, stdout);
32
-
33
- if (signature_check.gpg_output)
34
- fputs(signature_check.gpg_output, stderr);
29
+ print_signature_buffer(&signature_check, verbose ? GPG_VERIFY_VERBOSE : 0);
30
31
signature_check_clear(&signature_check);
32
return ret;
builtin/verify-tag.c
+5
-4
@@ -27,14 +27,15 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
27
memset(&sigc, 0, sizeof(sigc));
28
29
len = parse_signature(buf, size);
30
- if (verbose)
31
- write_in_full(1, buf, len);
30
33
- if (size == len)
31
+ if (size == len) {
32
+ if (verbose)
33
+ write_in_full(1, buf, len);
34
return error("no signature found");
35
+ }
36
37
ret = check_signature(buf, len, buf + len, size - len, &sigc);
37
- fputs(sigc.gpg_output, stderr);
38
+ print_signature_buffer(&sigc, verbose ? GPG_VERIFY_VERBOSE : 0);
39
40
signature_check_clear(&sigc);
41
return ret;
gpg-interface.c
+9
@@ -85,6 +85,15 @@ int check_signature(const char *payload, size_t plen, const char *signature,
85
return sigc->result != 'G' && sigc->result != 'U';
86
}
87
88
+void print_signature_buffer(const struct signature_check *sigc, unsigned flags)
89
+{
90
+ if (flags & GPG_VERIFY_VERBOSE && sigc->payload)
91
+ fputs(sigc->payload, stdout);
92
+
93
+ if (sigc->gpg_output)
94
+ fputs(sigc->gpg_output, stderr);
95
+}
96
+
97
/*
98
* Look at GPG signed content (e.g. a signed tag object), whose
99
* payload is followed by a detached signature on it. Return the
gpg-interface.h
+3
@@ -1,6 +1,8 @@
1
#ifndef GPG_INTERFACE_H
2
#define GPG_INTERFACE_H
3
4
+#define GPG_VERIFY_VERBOSE 1
5
+
6
struct signature_check {
7
char *payload;
8
char *gpg_output;
@@ -29,5 +31,6 @@ extern void set_signing_key(const char *);
31
extern const char *get_signing_key(void);
32
extern int check_signature(const char *payload, size_t plen,
33
const char *signature, size_t slen, struct signature_check *sigc);
34
+void print_signature_buffer(const struct signature_check *sigc, unsigned flags);
35
36
#endif