Skip to content

Commit 0b11a84

Browse files
mgornygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da6cf1b commit 0b11a84

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

gpg-interface.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,27 @@ void signature_check_clear(struct signature_check *sigc)
7777

7878
/* An exclusive status -- only one of them can appear in output */
7979
#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)
8087

8188
static struct {
8289
char result;
8390
const char *check;
8491
unsigned int flags;
8592
} 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 },
8895
{ 'U', "TRUST_NEVER", 0 },
8996
{ '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 },
94101
};
95102

96103
static void parse_gpg_output(struct signature_check *sigc)
@@ -117,13 +124,13 @@ static void parse_gpg_output(struct signature_check *sigc)
117124
}
118125

119126
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) {
122129
next = strchrnul(line, ' ');
123130
free(sigc->key);
124131
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)) {
127134
line = next + 1;
128135
next = strchrnul(line, '\n');
129136
free(sigc->signer);

0 commit comments

Comments
 (0)