gpg-interface.c: use flags to determine key/signer info presence

Replace the logic used to determine whether key and signer information is present to use explicit flags in sigcheck_gpg_status[] array. This is more future-proof, since it makes it possible to add additional statuses without having to explicitly update the conditions. Signed-off-by: Michał Górny <mgorny@gentoo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michał Górny committed Oct 22, 2018 at 18:38 UTC 0b11a84e1ba26fa3c9995f19e224848d8afc9bcf
1 file changed +17 -10
gpg-interface.c
+17 -10
@@ -77,20 +77,27 @@ void signature_check_clear(struct signature_check *sigc)
77
78 /* An exclusive status -- only one of them can appear in output */
79 #define GPG_STATUS_EXCLUSIVE (1<<0)
80 +/* The status includes key identifier */
81 +#define GPG_STATUS_KEYID (1<<1)
82 +/* The status includes user identifier */
83 +#define GPG_STATUS_UID (1<<2)
84 +
85 +/* Short-hand for standard exclusive *SIG status with keyid & UID */
86 +#define GPG_STATUS_STDSIG (GPG_STATUS_EXCLUSIVE|GPG_STATUS_KEYID|GPG_STATUS_UID)
87
88 static struct {
89 char result;
90 const char *check;
91 unsigned int flags;
92 } sigcheck_gpg_status[] = {
86 - { 'G', "GOODSIG ", GPG_STATUS_EXCLUSIVE },
87 - { 'B', "BADSIG ", GPG_STATUS_EXCLUSIVE },
93 + { 'G', "GOODSIG ", GPG_STATUS_STDSIG },
94 + { 'B', "BADSIG ", GPG_STATUS_STDSIG },
95 { 'U', "TRUST_NEVER", 0 },
96 { 'U', "TRUST_UNDEFINED", 0 },
90 - { 'E', "ERRSIG ", GPG_STATUS_EXCLUSIVE },
91 - { 'X', "EXPSIG ", GPG_STATUS_EXCLUSIVE },
92 - { 'Y', "EXPKEYSIG ", GPG_STATUS_EXCLUSIVE },
93 - { 'R', "REVKEYSIG ", GPG_STATUS_EXCLUSIVE },
97 + { 'E', "ERRSIG ", GPG_STATUS_EXCLUSIVE|GPG_STATUS_KEYID },
98 + { 'X', "EXPSIG ", GPG_STATUS_STDSIG },
99 + { 'Y', "EXPKEYSIG ", GPG_STATUS_STDSIG },
100 + { 'R', "REVKEYSIG ", GPG_STATUS_STDSIG },
101 };
102
103 static void parse_gpg_output(struct signature_check *sigc)
@@ -117,13 +124,13 @@ static void parse_gpg_output(struct signature_check *sigc)
124 }
125
126 sigc->result = sigcheck_gpg_status[i].result;
120 - /* The trust messages are not followed by key/signer information */
121 - if (sigc->result != 'U') {
127 + /* Do we have key information? */
128 + if (sigcheck_gpg_status[i].flags & GPG_STATUS_KEYID) {
129 next = strchrnul(line, ' ');
130 free(sigc->key);
131 sigc->key = xmemdupz(line, next - line);
125 - /* The ERRSIG message is not followed by signer information */
126 - if (*next && sigc->result != 'E') {
132 + /* Do we have signer information? */
133 + if (*next && (sigcheck_gpg_status[i].flags & GPG_STATUS_UID)) {
134 line = next + 1;
135 next = strchrnul(line, '\n');
136 free(sigc->signer);