diff mbox series

[1/3] gpg-interface.c: use flags to determine key/signer info presence

Message ID 20181022163821.23523-1-mgorny@gentoo.org (mailing list archive)
State New, archived
Headers show
Series [1/3] gpg-interface.c: use flags to determine key/signer info presence | expand

Commit Message

Michał Górny Oct. 22, 2018, 4:38 p.m. UTC
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>
---
 gpg-interface.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

Comments

brian m. carlson Oct. 23, 2018, 10:56 p.m. UTC | #1
On Mon, Oct 22, 2018 at 06:38:19PM +0200, Michał Górny wrote:
> 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.

This series looks good to me.  I was going to ask after patch 2 whether
you were printing the subkey or primary key fingerprint, and then you
answered my question in patch 3.  Thanks for including both.
Junio C Hamano Oct. 24, 2018, 3:10 a.m. UTC | #2
"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> On Mon, Oct 22, 2018 at 06:38:19PM +0200, Michał Górny wrote:
>> 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.
>
> This series looks good to me.  I was going to ask after patch 2 whether
> you were printing the subkey or primary key fingerprint, and then you
> answered my question in patch 3.  Thanks for including both.

Yeah, this looks good to me too.  Thanks, both.
diff mbox series

Patch

diff --git a/gpg-interface.c b/gpg-interface.c
index d72a43b77..c7cd24ec0 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -77,20 +77,27 @@  void signature_check_clear(struct signature_check *sigc)
 
 /* An exclusive status -- only one of them can appear in output */
 #define GPG_STATUS_EXCLUSIVE	(1<<0)
+/* The status includes key identifier */
+#define GPG_STATUS_KEYID	(1<<1)
+/* The status includes user identifier */
+#define GPG_STATUS_UID		(1<<2)
+
+/* Short-hand for standard exclusive *SIG status with keyid & UID */
+#define GPG_STATUS_STDSIG	(GPG_STATUS_EXCLUSIVE|GPG_STATUS_KEYID|GPG_STATUS_UID)
 
 static struct {
 	char result;
 	const char *check;
 	unsigned int flags;
 } sigcheck_gpg_status[] = {
-	{ 'G', "GOODSIG ", GPG_STATUS_EXCLUSIVE },
-	{ 'B', "BADSIG ", GPG_STATUS_EXCLUSIVE },
+	{ 'G', "GOODSIG ", GPG_STATUS_STDSIG },
+	{ 'B', "BADSIG ", GPG_STATUS_STDSIG },
 	{ 'U', "TRUST_NEVER", 0 },
 	{ 'U', "TRUST_UNDEFINED", 0 },
-	{ 'E', "ERRSIG ", GPG_STATUS_EXCLUSIVE },
-	{ 'X', "EXPSIG ", GPG_STATUS_EXCLUSIVE },
-	{ 'Y', "EXPKEYSIG ", GPG_STATUS_EXCLUSIVE },
-	{ 'R', "REVKEYSIG ", GPG_STATUS_EXCLUSIVE },
+	{ 'E', "ERRSIG ", GPG_STATUS_EXCLUSIVE|GPG_STATUS_KEYID },
+	{ 'X', "EXPSIG ", GPG_STATUS_STDSIG },
+	{ 'Y', "EXPKEYSIG ", GPG_STATUS_STDSIG },
+	{ 'R', "REVKEYSIG ", GPG_STATUS_STDSIG },
 };
 
 static void parse_gpg_output(struct signature_check *sigc)
@@ -117,13 +124,13 @@  static void parse_gpg_output(struct signature_check *sigc)
 				}
 
 				sigc->result = sigcheck_gpg_status[i].result;
-				/* The trust messages are not followed by key/signer information */
-				if (sigc->result != 'U') {
+				/* Do we have key information? */
+				if (sigcheck_gpg_status[i].flags & GPG_STATUS_KEYID) {
 					next = strchrnul(line, ' ');
 					free(sigc->key);
 					sigc->key = xmemdupz(line, next - line);
-					/* The ERRSIG message is not followed by signer information */
-					if (*next && sigc->result != 'E') {
+					/* Do we have signer information? */
+					if (*next && (sigcheck_gpg_status[i].flags & GPG_STATUS_UID)) {
 						line = next + 1;
 						next = strchrnul(line, '\n');
 						free(sigc->signer);