Split GPG interface into its own helper library
PATCH v2 1/1 Split GPG interface into its own helper library
This mostly moves existing code from builtin/tag.c (for signing) and builtin/verify-tag.c (for verifying) to a new gpg-interface.c file to provide a more generic library interface.
Signed-off-by Junio C Hamano <[email protected]>
---
* This is a re-roll of what was queued as part of jc/signed-push topic. The helper is now aware of user.signingkey configuration and can use it across all the future users.
Makefile | 2 + builtin/tag.c | 76 +++----------------------------- builtin/verify-tag.c | 35 +------------- gpg-interface.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++ gpg-interface.h | 14 ++++++ 5 files changed, 144 insertions(+), 102 deletions(-) create mode 100644 gpg-interface.c create mode 100644 gpg-interface.h
Makefile +2 -0
@@ -530,6 +530,7 @@ LIB_H += exec_cmd.h LIB_H += fsck.h LIB_H += gettext.h LIB_H += git-compat-util.h +LIB_H += gpg-interface.h LIB_H += graph.h LIB_H += grep.h LIB_H += hash.h
@@ -620,6 +621,7 @@ LIB_OBJS += entry.o LIB_OBJS += environment.o LIB_OBJS += exec_cmd.o LIB_OBJS += fsck.o +LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o LIB_OBJS += grep.o LIB_OBJS += hash.o
builtin/tag.c +6 -70
108 lines not on this page · raw message
builtin/verify-tag.c +3 -32
@@ -11,6 +11,7 @@#include "run-command.h" #include <signal.h> #include "parse-options.h" +#include "gpg-interface.h" static const char *const verify_tag_usage[] = {"git verify-tag [-v|--verbose] <tag>..." ,
@@ -19,42 +20,12 @@ static const char * const verify_tag_usage[] = {static int run_gpg_verify (const char *buf,unsigned long size,int verbose) { -struct child_process gpg; -const char *args_gpg[] = {"gpg" ,"--verify" ,"FILE" ,"-" ,NULL }; -char path[PATH_MAX ]; -size_t len; -int fd, ret; +int len; - fd =git_mkstemp (path,PATH_MAX ,".git_vtag_tmpXXXXXX" ); -if (fd <0 ) -return error ("could not create temporary file '%s': %s" , - path,strerror (errno)); -if (write_in_full (fd, buf, size) <0 ) -return error ("failed writing temporary file '%s': %s" , - path,strerror (errno)); -close (fd); - -/* find the length without signature */ len =parse_signature (buf, size);if (verbose)write_in_full (1 , buf, len); - -memset (&gpg,0 ,sizeof (gpg)); - gpg.argv = args_gpg; - gpg.in =-1 ; - args_gpg[2 ] = path; -if (start_command (&gpg)) { -unlink (path); -return error ("could not run gpg." ); - } - -write_in_full (gpg.in, buf, len); -close (gpg.in); - ret =finish_command (&gpg); - -unlink_or_warn (path); - -return ret; +return verify_signed_buffer (buf, size, len); }static int verify_tag (const char *name,int verbose)
gpg-interface.c new file +119 -0
119 lines not on this page · raw message
gpg-interface.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef GPG_INTERFACE_H +#define GPG_INTERFACE_H + +/* +* Copyright (c) 2011, Google Inc. +*/ + +extern int sign_buffer (struct strbuf *buffer,const char *signing_key); +extern int verify_signed_buffer (const char *buffer,size_t total,size_t payload); +extern int git_gpg_config (const char *,const char *,void *); +extern void set_signing_key (const char *); +extern const char *get_signing_key (void ); + +#endif
Signature · 1 line
1.7.7.138.g7f41b6