[3/5] Signing API: Migrated to the new signing interface API
diff mbox series

Message ID GSHQf1g8UZwwtt5kzbA3GmLTulyYELqEIes51wFqZMG6FP5WpWZwsfnsV5cx74e5gbGBgRaNGY1B-SVRi3PMUZoIg3APf9XAa3bLMw8HHDw=@pm.me
State New
Headers show
Series
  • New signing interface API with pluggable drivers
Related show

Commit Message

Ibrahim El Aug. 26, 2019, 7:58 p.m. UTC
From: Ibrahim El Rhezzali <ibrahim.el@pm.me>

0affa9e2a Migrated to the new signing interface API

Updating the code to use the new signing interface API. Old GPG interface code is commented and not used

Signed-off-by: Ibrahim El <ibrahim.el@pm.me>
---
 builtin/am.c            |  3 ++-
 builtin/commit-tree.c   |  4 ++--
 builtin/commit.c        |  4 ++--
 builtin/fmt-merge-msg.c |  2 +-
 builtin/log.c           |  4 ++--
 builtin/merge.c         |  4 ++--
 builtin/push.c          |  3 ++-
 builtin/receive-pack.c  |  4 ++--
 builtin/send-pack.c     |  4 ++--
 builtin/tag.c           | 13 +++++++------
 builtin/verify-commit.c | 12 ++++++------
 builtin/verify-tag.c    | 10 +++++-----
 commit.c                | 13 +++++++------
 commit.h                |  4 ++--
 gpg-interface.c         |  5 ++++-
 gpg-interface.h         |  3 +++
 log-tree.c              |  2 +-
 pretty.c                |  8 ++++----
 ref-filter.c            |  1 +
 send-pack.c             |  5 +++--
 sequencer.c             |  3 ++-
 tag.c                   | 10 +++++-----
 22 files changed, 67 insertions(+), 54 deletions(-)

Patch
diff mbox series

diff --git a/builtin/am.c b/builtin/am.c
index 78389d08b..a76efdd5d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -34,6 +34,7 @@ 
 #include "string-list.h"
 #include "packfile.h"
 #include "repository.h"
+#include "signing-interface.h"
 
 /**
  * Returns the length of the first line of msg.
@@ -2143,7 +2144,7 @@  static int git_am_config(const char *k, const char *v, void *cb)
 {
 	int status;
 
-	status = git_gpg_config(k, v, NULL);
+	status = git_signing_config(k, v, NULL);
 	if (status)
 		return status;
 
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index b866d8395..06bc5016d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -11,7 +11,7 @@ 
 #include "tree.h"
 #include "builtin.h"
 #include "utf8.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "parse-options.h"
 
 static const char * const commit_tree_usage[] = {
@@ -38,7 +38,7 @@  static void new_parent(struct commit *parent, struct commit_list **parents_p)
 
 static int commit_tree_config(const char *var, const char *value, void *cb)
 {
-	int status = git_gpg_config(var, value, NULL);
+	int status = git_signing_config(var, value, NULL);
 	if (status)
 		return status;
 	return git_default_config(var, value, cb);
diff --git a/builtin/commit.c b/builtin/commit.c
index 1c9e8e222..3b446a029 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -29,7 +29,7 @@ 
 #include "unpack-trees.h"
 #include "quote.h"
 #include "submodule.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "column.h"
 #include "sequencer.h"
 #include "mailmap.h"
@@ -1437,7 +1437,7 @@  static int git_commit_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 
-	status = git_gpg_config(k, v, NULL);
+	status = git_signing_config(k, v, NULL);
 	if (status)
 		return status;
 	return git_status_config(k, v, s);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index a4615587f..2dd0e9367 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -10,7 +10,7 @@ 
 #include "string-list.h"
 #include "branch.h"
 #include "fmt-merge-msg.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "repository.h"
 #include "commit-reach.h"
 
diff --git a/builtin/log.c b/builtin/log.c
index 7c8767d3b..96507f0d9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -28,7 +28,7 @@ 
 #include "streaming.h"
 #include "version.h"
 #include "mailmap.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "progress.h"
 #include "commit-slab.h"
 #include "repository.h"
@@ -465,7 +465,7 @@  static int git_log_config(const char *var, const char *value, void *cb)
 
 	if (grep_config(var, value, cb) < 0)
 		return -1;
-	if (git_gpg_config(var, value, cb) < 0)
+	if (git_signing_config(var, value, cb) < 0)
 		return -1;
 	return git_diff_ui_config(var, value, cb);
 }
diff --git a/builtin/merge.c b/builtin/merge.c
index 6e99aead4..67a0bcb35 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -31,7 +31,7 @@ 
 #include "resolve-undo.h"
 #include "remote.h"
 #include "fmt-merge-msg.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "sequencer.h"
 #include "string-list.h"
 #include "packfile.h"
@@ -636,7 +636,7 @@  static int git_merge_config(const char *k, const char *v, void *cb)
 	status = fmt_merge_msg_config(k, v, cb);
 	if (status)
 		return status;
-	status = git_gpg_config(k, v, NULL);
+	status = git_signing_config(k, v, NULL);
 	if (status)
 		return status;
 	return git_diff_ui_config(k, v, cb);
diff --git a/builtin/push.c b/builtin/push.c
index 021dd3b1e..74a6758cd 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -14,6 +14,7 @@ 
 #include "submodule-config.h"
 #include "send-pack.h"
 #include "color.h"
+#include "signing-interface.h"
 
 static const char * const push_usage[] = {
 	N_("git push [<options>] [<repository> [<refspec>...]]"),
@@ -479,7 +480,7 @@  static int git_push_config(const char *k, const char *v, void *cb)
 	int *flags = cb;
 	int status;
 
-	status = git_gpg_config(k, v, NULL);
+	status = git_signing_config(k, v, NULL);
 	if (status)
 		return status;
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 77b712245..1a90dea5a 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -19,7 +19,7 @@ 
 #include "argv-array.h"
 #include "version.h"
 #include "tag.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "sigchain.h"
 #include "fsck.h"
 #include "tmp-objdir.h"
@@ -73,7 +73,7 @@  static int shallow_update;
 static const char *alt_shallow_file;
 static struct strbuf push_cert = STRBUF_INIT;
 static struct object_id push_cert_oid;
-static struct signature_check sigcheck;
+static struct signature sigcheck;
 static const char *push_cert_nonce;
 static const char *cert_nonce_seed;
 
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 098ebf22d..ba21fb2df 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -12,7 +12,7 @@ 
 #include "transport.h"
 #include "version.h"
 #include "sha1-array.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "gettext.h"
 #include "protocol.h"
 
@@ -101,7 +101,7 @@  static void print_helper_status(struct ref *ref)
 
 static int send_pack_config(const char *k, const char *v, void *cb)
 {
-	git_gpg_config(k, v, NULL);
+	git_signing_config(k, v, NULL);
 
 	if (!strcmp(k, "push.gpgsign")) {
 		const char *value;
diff --git a/builtin/tag.c b/builtin/tag.c
index ef37dccf8..a52aa54c0 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -16,7 +16,7 @@ 
 #include "parse-options.h"
 #include "diff.h"
 #include "revision.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "sha1-array.h"
 #include "column.h"
 #include "ref-filter.h"
@@ -111,10 +111,10 @@  static int verify_tag(const char *name, const char *ref,
 {
 	int flags;
 	const struct ref_format *format = cb_data;
-	flags = GPG_VERIFY_VERBOSE;
+	flags = OUTPUT_VERBOSE;
 
 	if (format->format)
-		flags = GPG_VERIFY_OMIT_STATUS;
+		flags = OUTPUT_OMIT_STATUS;
 
 	if (gpg_verify_tag(oid, name, flags))
 		return -1;
@@ -127,7 +127,8 @@  static int verify_tag(const char *name, const char *ref,
 
 static int do_sign(struct strbuf *buffer)
 {
-	return sign_buffer(buffer, buffer, get_signing_key());
+	extern enum signature_type default_type;
+	return sign_buffer(buffer, buffer, get_signing_key(default_type));
 }
 
 static const char tag_template[] =
@@ -151,7 +152,7 @@  static int git_tag_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
-	status = git_gpg_config(var, value, cb);
+	status = git_signing_config(var, value, cb);
 	if (status)
 		return status;
 	if (!strcmp(var, "tag.forcesignannotated")) {
@@ -447,7 +448,7 @@  int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	if (keyid) {
 		opt.sign = 1;
-		set_signing_key(keyid);
+		set_signing_key(keyid, default_type);
 	}
 	create_tag_object = (opt.sign || annotate || msg.given || msgfile);
 
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 4b9e823f8..0f701ee70 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -14,7 +14,7 @@ 
 #include "run-command.h"
 #include <signal.h>
 #include "parse-options.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 
 static const char * const verify_commit_usage[] = {
 		N_("git verify-commit [-v | --verbose] <commit>..."),
@@ -23,7 +23,7 @@  static const char * const verify_commit_usage[] = {
 
 static int run_gpg_verify(struct commit *commit, unsigned flags)
 {
-	struct signature_check signature_check;
+	struct signature signature_check;
 	int ret;
 
 	memset(&signature_check, 0, sizeof(signature_check));
@@ -31,7 +31,7 @@  static int run_gpg_verify(struct commit *commit, unsigned flags)
 	ret = check_commit_signature(commit, &signature_check);
 	print_signature_buffer(&signature_check, flags);
 
-	signature_check_clear(&signature_check);
+	signature_clear(&signature_check);
 	return ret;
 }
 
@@ -55,7 +55,7 @@  static int verify_commit(const char *name, unsigned flags)
 
 static int git_verify_commit_config(const char *var, const char *value, void *cb)
 {
-	int status = git_gpg_config(var, value, cb);
+	int status = git_signing_config(var, value, cb);
 	if (status)
 		return status;
 	return git_default_config(var, value, cb);
@@ -67,7 +67,7 @@  int cmd_verify_commit(int argc, const char **argv, const char *prefix)
 	unsigned flags = 0;
 	const struct option verify_commit_options[] = {
 		OPT__VERBOSE(&verbose, N_("print commit contents")),
-		OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
+		OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), OUTPUT_RAW),
 		OPT_END()
 	};
 
@@ -79,7 +79,7 @@  int cmd_verify_commit(int argc, const char **argv, const char *prefix)
 		usage_with_options(verify_commit_usage, verify_commit_options);
 
 	if (verbose)
-		flags |= GPG_VERIFY_VERBOSE;
+		flags |= OUTPUT_VERBOSE;
 
 	/* sometimes the program was terminated because this signal
 	 * was received in the process of writing the gpg input: */
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 6fa04b751..d25f47d38 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -12,7 +12,7 @@ 
 #include "run-command.h"
 #include <signal.h>
 #include "parse-options.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "ref-filter.h"
 
 static const char * const verify_tag_usage[] = {
@@ -22,7 +22,7 @@  static const char * const verify_tag_usage[] = {
 
 static int git_verify_tag_config(const char *var, const char *value, void *cb)
 {
-	int status = git_gpg_config(var, value, cb);
+	int status = git_signing_config(var, value, cb);
 	if (status)
 		return status;
 	return git_default_config(var, value, cb);
@@ -35,7 +35,7 @@  int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	struct ref_format format = REF_FORMAT_INIT;
 	const struct option verify_tag_options[] = {
 		OPT__VERBOSE(&verbose, N_("print tag contents")),
-		OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
+		OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), OUTPUT_RAW),
 		OPT_STRING(0, "format", &format.format, N_("format"), N_("format to use for the output")),
 		OPT_END()
 	};
@@ -48,13 +48,13 @@  int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 		usage_with_options(verify_tag_usage, verify_tag_options);
 
 	if (verbose)
-		flags |= GPG_VERIFY_VERBOSE;
+		flags |= OUTPUT_VERBOSE;
 
 	if (format.format) {
 		if (verify_ref_format(&format))
 			usage_with_options(verify_tag_usage,
 					   verify_tag_options);
-		flags |= GPG_VERIFY_OMIT_STATUS;
+		flags |= OUTPUT_OMIT_STATUS;
 	}
 
 	while (i < argc) {
diff --git a/commit.c b/commit.c
index 8fa1883c6..2727c9231 100644
--- a/commit.c
+++ b/commit.c
@@ -10,7 +10,7 @@ 
 #include "revision.h"
 #include "notes.h"
 #include "alloc.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "mergesort.h"
 #include "commit-slab.h"
 #include "prio-queue.h"
@@ -953,8 +953,9 @@  static int do_sign_commit(struct strbuf *buf, const char *keyid)
 	else
 		inspos = eoh - buf->buf + 1;
 
-	if (!keyid || !*keyid)
-		keyid = get_signing_key();
+	if (!keyid || !*keyid) {
+		keyid = get_signing_key(default_type);
+	}
 	if (sign_buffer(buf, &sig, keyid)) {
 		strbuf_release(&sig);
 		return -1;
@@ -1092,7 +1093,7 @@  static void handle_signed_tag(struct commit *parent, struct commit_extra_header
 	free(buf);
 }
 
-int check_commit_signature(const struct commit *commit, struct signature_check *sigc)
+int check_commit_signature(const struct commit *commit, struct signature *sigc)
 {
 	struct strbuf payload = STRBUF_INIT;
 	struct strbuf signature = STRBUF_INIT;
@@ -1115,7 +1116,7 @@  int check_commit_signature(const struct commit *commit, struct signature_check *
 void verify_merge_signature(struct commit *commit, int verbosity)
 {
 	char hex[GIT_MAX_HEXSZ + 1];
-	struct signature_check signature_check;
+	struct signature signature_check;
 	memset(&signature_check, 0, sizeof(signature_check));
 
 	check_commit_signature(commit, &signature_check);
@@ -1137,7 +1138,7 @@  void verify_merge_signature(struct commit *commit, int verbosity)
 		printf(_("Commit %s has a good GPG signature by %s\n"),
 		       hex, signature_check.signer);
 
-	signature_check_clear(&signature_check);
+	signature_clear(&signature_check);
 }
 
 void append_merge_tag_headers(struct commit_list *parents,
diff --git a/commit.h b/commit.h
index f5295ca7f..f5a942fc5 100644
--- a/commit.h
+++ b/commit.h
@@ -5,7 +5,7 @@ 
 #include "tree.h"
 #include "strbuf.h"
 #include "decorate.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "string-list.h"
 #include "pretty.h"
 #include "commit-slab.h"
@@ -370,7 +370,7 @@  int remove_signature(struct strbuf *buf);
  * at all.  This may allocate memory for sig->gpg_output, sig->gpg_status,
  * sig->signer and sig->key.
  */
-int check_commit_signature(const struct commit *commit, struct signature_check *sigc);
+int check_commit_signature(const struct commit *commit, struct signature *sigc);
 
 /* record author-date for each commit object */
 struct author_date_slab;
diff --git a/gpg-interface.c b/gpg-interface.c
index 8ed274533..5e7dee6fe 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -6,6 +6,7 @@ 
 #include "sigchain.h"
 #include "tempfile.h"
 
+#if 0
 static char *configured_signing_key;
 struct gpg_format {
 	const char *name;
@@ -289,7 +290,7 @@  const char *get_signing_key(void)
 }
 
 int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key)
-{
+{	
 	struct child_process gpg = CHILD_PROCESS_INIT;
 	int ret;
 	size_t i, j, bottom;
@@ -376,3 +377,5 @@  int verify_signed_buffer(const char *payload, size_t payload_size,
 
 	return ret;
 }
+
+#endif
\ No newline at end of file
diff --git a/gpg-interface.h b/gpg-interface.h
index 3e624ec28..c808d1685 100644
--- a/gpg-interface.h
+++ b/gpg-interface.h
@@ -1,6 +1,7 @@ 
 #ifndef GPG_INTERFACE_H
 #define GPG_INTERFACE_H
 
+#if 0
 struct strbuf;
 
 #define GPG_VERIFY_VERBOSE		1
@@ -65,3 +66,5 @@  void print_signature_buffer(const struct signature_check *sigc,
 			    unsigned flags);
 
 #endif
+
+#endif
\ No newline at end of file
diff --git a/log-tree.c b/log-tree.c
index 1e56df62a..c13a7e06d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -11,7 +11,7 @@ 
 #include "refs.h"
 #include "string-list.h"
 #include "color.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "sequencer.h"
 #include "line-log.h"
 #include "help.h"
diff --git a/pretty.c b/pretty.c
index ced048525..f315755c3 100644
--- a/pretty.c
+++ b/pretty.c
@@ -10,7 +10,7 @@ 
 #include "notes.h"
 #include "color.h"
 #include "reflog-walk.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "trailer.h"
 
 static char *user_format;
@@ -771,7 +771,7 @@  struct format_commit_context {
 	const struct pretty_print_context *pretty_ctx;
 	unsigned commit_header_parsed:1;
 	unsigned commit_message_parsed:1;
-	struct signature_check signature_check;
+	struct signature signature_check;
 	enum flush_type flush_type;
 	enum trunc_type truncate;
 	const char *message;
@@ -1292,8 +1292,8 @@  static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 			check_commit_signature(c->commit, &(c->signature_check));
 		switch (placeholder[1]) {
 		case 'G':
-			if (c->signature_check.gpg_output)
-				strbuf_addstr(sb, c->signature_check.gpg_output);
+			if (c->signature_check.output.buf)
+				strbuf_addstr(sb, c->signature_check.output.buf);
 			break;
 		case '?':
 			switch (c->signature_check.result) {
diff --git a/ref-filter.c b/ref-filter.c
index 8500671bc..277fcc04e 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -20,6 +20,7 @@ 
 #include "commit-slab.h"
 #include "commit-graph.h"
 #include "commit-reach.h"
+#include "signing-interface.h"
 
 static struct ref_msg {
 	const char *gone;
diff --git a/send-pack.c b/send-pack.c
index 6dc16c321..6db779964 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -13,7 +13,7 @@ 
 #include "transport.h"
 #include "version.h"
 #include "sha1-array.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "cache.h"
 
 int option_parse_push_signed(const struct option *opt,
@@ -269,7 +269,8 @@  static int generate_push_cert(struct strbuf *req_buf,
 {
 	const struct ref *ref;
 	struct string_list_item *item;
-	char *signing_key = xstrdup(get_signing_key());
+	extern enum signature_type default_type;
+	char *signing_key = xstrdup(get_signing_key(default_type));
 	const char *cp, *np;
 	struct strbuf cert = STRBUF_INIT;
 	int update_seen = 0;
diff --git a/sequencer.c b/sequencer.c
index ab74b6baf..e3cfe40d2 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -32,6 +32,7 @@ 
 #include "alias.h"
 #include "commit-reach.h"
 #include "rebase-interactive.h"
+#include "signing-interface.h"
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
@@ -197,7 +198,7 @@  static int git_sequencer_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 
-	status = git_gpg_config(k, v, NULL);
+	status = git_signing_config(k, v, NULL);
 	if (status)
 		return status;
 
diff --git a/tag.c b/tag.c
index 7445b8f6e..d9bbf5249 100644
--- a/tag.c
+++ b/tag.c
@@ -5,14 +5,14 @@ 
 #include "tree.h"
 #include "blob.h"
 #include "alloc.h"
-#include "gpg-interface.h"
+#include "signing-interface.h"
 #include "packfile.h"
 
 const char *tag_type = "tag";
 
 static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
 {
-	struct signature_check sigc;
+	struct signature sigc;
 	size_t payload_size;
 	int ret;
 
@@ -21,7 +21,7 @@  static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
 	payload_size = parse_signature(buf, size);
 
 	if (size == payload_size) {
-		if (flags & GPG_VERIFY_VERBOSE)
+		if (flags & OUTPUT_VERBOSE)
 			write_in_full(1, buf, payload_size);
 		return error("no signature found");
 	}
@@ -29,10 +29,10 @@  static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
 	ret = check_signature(buf, payload_size, buf + payload_size,
 				size - payload_size, &sigc);
 
-	if (!(flags & GPG_VERIFY_OMIT_STATUS))
+	if (!(flags & OUTPUT_OMIT_STATUS))
 		print_signature_buffer(&sigc, flags);
 
-	signature_check_clear(&sigc);
+	signature_clear(&sigc);
 	return ret;
 }