[ostree] libotutil: Establish a place for GPG utilities



commit ceacc5720647a4d1661889431786c267153d536c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Apr 26 18:08:20 2015 -0400

    libotutil: Establish a place for GPG utilities
    
    Add ot-gpg-utils.[ch] and move _ostree_gpg_error_to_gio_error() here.

 Makefile-libostree.am                            |    4 +-
 Makefile-otutil.am                               |    6 ++-
 Makefile.am                                      |    4 ++
 src/libostree/ostree-gpg-verifier.c              |    9 ++--
 src/libostree/ostree-gpg-verify-result-private.h |    7 +--
 src/libostree/ostree-gpg-verify-result.c         |   38 +--------------
 src/libostree/ostree-repo.c                      |   20 +++-----
 src/libotutil/ot-gpg-utils.c                     |   57 ++++++++++++++++++++++
 src/libotutil/ot-gpg-utils.h                     |   30 +++++++++++
 src/libotutil/otutil.h                           |    1 +
 10 files changed, 112 insertions(+), 64 deletions(-)
---
diff --git a/Makefile-libostree.am b/Makefile-libostree.am
index 06eeaaa..776f551 100644
--- a/Makefile-libostree.am
+++ b/Makefile-libostree.am
@@ -112,9 +112,9 @@ libostree_1_la_SOURCES += \
 endif
 
 libostree_1_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/bsdiff -I$(srcdir)/libglnx -I$(srcdir)/src/libotutil 
-I$(srcdir)/src/libostree \
-       $(OT_INTERNAL_GIO_UNIX_CFLAGS) $(OT_DEP_LZMA_CFLAGS) $(OT_DEP_ZLIB_CFLAGS)
+       $(OT_INTERNAL_GIO_UNIX_CFLAGS) $(OT_INTERNAL_GPGME_CFLAGS) $(OT_DEP_LZMA_CFLAGS) $(OT_DEP_ZLIB_CFLAGS)
 libostree_1_la_LDFLAGS = -version-number 1:0:0 -Bsymbolic-functions -export-symbols-regex '^ostree_'
-libostree_1_la_LIBADD = libotutil.la libbupsplit.la libglnx.la libbsdiff.la libostree-kernel-args.la 
$(OT_INTERNAL_GIO_UNIX_LIBS) $(OT_DEP_LZMA_LIBS) $(OT_DEP_ZLIB_LIBS) $(GPGME_LIBS)
+libostree_1_la_LIBADD = libotutil.la libbupsplit.la libglnx.la libbsdiff.la libostree-kernel-args.la 
$(OT_INTERNAL_GIO_UNIX_LIBS) $(OT_INTERNAL_GPGME_LIBS) $(OT_DEP_LZMA_LIBS) $(OT_DEP_ZLIB_LIBS)
 
 if USE_LIBARCHIVE
 libostree_1_la_CFLAGS += $(OT_DEP_LIBARCHIVE_CFLAGS)
diff --git a/Makefile-otutil.am b/Makefile-otutil.am
index 3a2b3dc..efcb04b 100644
--- a/Makefile-otutil.am
+++ b/Makefile-otutil.am
@@ -36,10 +36,12 @@ libotutil_la_SOURCES = \
        src/libotutil/ot-variant-utils.h \
        src/libotutil/ot-gio-utils.c \
        src/libotutil/ot-gio-utils.h \
+       src/libotutil/ot-gpg-utils.c \
+       src/libotutil/ot-gpg-utils.h \
        src/libotutil/otutil.c \
        src/libotutil/otutil.h \
        src/libotutil/ot-tool-util.c \
        src/libotutil/ot-tool-util.h \
        $(NULL)
-libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libglnx -I$(srcdir)/src/libotutil 
-DLOCALEDIR=\"$(datadir)/locale\" $(OT_INTERNAL_GIO_UNIX_CFLAGS)
-libotutil_la_LIBADD = $(OT_INTERNAL_GIO_UNIX_LIBS)
+libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libglnx -I$(srcdir)/src/libotutil 
-DLOCALEDIR=\"$(datadir)/locale\" $(OT_INTERNAL_GIO_UNIX_CFLAGS) $(OT_INTERNAL_GPGME_CFLAGS)
+libotutil_la_LIBADD = $(OT_INTERNAL_GIO_UNIX_LIBS) $(OT_INTERNAL_GPGME_LIBS)
diff --git a/Makefile.am b/Makefile.am
index 810c2c7..103fc76 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,6 +39,10 @@ OT_INTERNAL_GIO_UNIX_LIBS = $(OT_DEP_GIO_UNIX_LIBS)
 OT_INTERNAL_SOUP_CFLAGS = $(OT_DEP_SOUP_CFLAGS)
 OT_INTERNAL_SOUP_LIBS = $(OT_DEP_SOUP_LIBS)
 
+# This canonicalizes the PKG_CHECK_MODULES or AM_PATH_GPGME results
+OT_INTERNAL_GPGME_CFLAGS = $(OT_DEP_GPGME_CFLAGS) $(GPGME_CFLAGS)
+OT_INTERNAL_GPGME_LIBS = $(OT_DEP_GPGME_LIBS) $(GPGME_LIBS)
+
 if BUILDOPT_INTROSPECTION
 include $(INTROSPECTION_MAKEFILE)
 GIRS =
diff --git a/src/libostree/ostree-gpg-verifier.c b/src/libostree/ostree-gpg-verifier.c
index dfa47eb..17282a9 100644
--- a/src/libostree/ostree-gpg-verifier.c
+++ b/src/libostree/ostree-gpg-verifier.c
@@ -29,7 +29,6 @@
 
 #include <stdlib.h>
 #include <glib/gstdio.h>
-#include <gpgme.h>
 
 typedef struct {
   GObjectClass parent_class;
@@ -187,7 +186,7 @@ override_gpgme_home_dir (gpgme_ctx_t gpg_ctx,
                                                  home_dir);
           if (gpg_error != GPG_ERR_NO_ERROR)
             {
-              _ostree_gpg_error_to_gio_error (gpg_error, error);
+              ot_gpgme_error_to_gio_error (gpg_error, error);
               goto out;
             }
 
@@ -278,7 +277,7 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier  *self,
                                        0 /* do not copy */);
   if (gpg_error != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (gpg_error, error);
+      ot_gpgme_error_to_gio_error (gpg_error, error);
       g_prefix_error (error, "Unable to read signed data: ");
       goto out;
     }
@@ -289,7 +288,7 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier  *self,
                                        0 /* do not copy */);
   if (gpg_error != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (gpg_error, error);
+      ot_gpgme_error_to_gio_error (gpg_error, error);
       g_prefix_error (error, "Unable to read signature: ");
       goto out;
     }
@@ -297,7 +296,7 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier  *self,
   gpg_error = gpgme_op_verify (result->context, signature_buffer, data_buffer, NULL);
   if (gpg_error != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (gpg_error, error);
+      ot_gpgme_error_to_gio_error (gpg_error, error);
       g_prefix_error (error, "Unable to complete signature verification: ");
       goto out;
     }
diff --git a/src/libostree/ostree-gpg-verify-result-private.h 
b/src/libostree/ostree-gpg-verify-result-private.h
index a91bd53..510728e 100644
--- a/src/libostree/ostree-gpg-verify-result-private.h
+++ b/src/libostree/ostree-gpg-verify-result-private.h
@@ -22,7 +22,7 @@
 
 #include "ostree-gpg-verify-result.h"
 
-#include <gpgme.h>
+#include "otutil.h"
 
 /**
  * OstreeGpgVerifyResult:
@@ -35,8 +35,3 @@ struct OstreeGpgVerifyResult {
   gpgme_ctx_t context;
   gpgme_verify_result_t details;
 };
-
-/* XXX Split these into a separate "GPGME utilities" file? */
-
-void _ostree_gpg_error_to_gio_error (gpgme_error_t gpg_error, GError **error);
-
diff --git a/src/libostree/ostree-gpg-verify-result.c b/src/libostree/ostree-gpg-verify-result.c
index a9e78bf..f1560a7 100644
--- a/src/libostree/ostree-gpg-verify-result.c
+++ b/src/libostree/ostree-gpg-verify-result.c
@@ -27,8 +27,6 @@
 
 #include "ostree-gpg-verify-result-private.h"
 
-#include <gpgme.h>
-
 /**
  * SECTION: libostree-gpg-verify-result
  * @title: GPG signature verification results
@@ -136,7 +134,7 @@ ostree_gpg_verify_result_initable_init (GInitable     *initable,
   gpg_error = gpgme_new (&result->context);
   if (gpg_error != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (gpg_error, error);
+      ot_gpgme_error_to_gio_error (gpg_error, error);
       g_prefix_error (error, "Unable to create context: ");
       goto out;
     }
@@ -594,37 +592,3 @@ ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
         }
     }
 }
-
-void
-_ostree_gpg_error_to_gio_error (gpgme_error_t   gpg_error,
-                                GError        **error)
-{
-  GIOErrorEnum errcode;
-
-  /* XXX This list is incomplete.  Add cases as needed. */
-
-  switch (gpg_error)
-    {
-      /* special case - shouldn't be here */
-      case GPG_ERR_NO_ERROR:
-        g_return_if_reached ();
-
-      /* special case - abort on out-of-memory */
-      case GPG_ERR_ENOMEM:
-        g_error ("%s: %s",
-                 gpgme_strsource (gpg_error),
-                 gpgme_strerror (gpg_error));
-
-      case GPG_ERR_INV_VALUE:
-        errcode = G_IO_ERROR_INVALID_ARGUMENT;
-        break;
-
-      default:
-        errcode = G_IO_ERROR_FAILED;
-        break;
-    }
-
-  g_set_error (error, G_IO_ERROR, errcode, "%s: %s",
-               gpgme_strsource (gpg_error),
-               gpgme_strerror (gpg_error));
-}
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 9c27fca..262d0e9 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -35,11 +35,7 @@
 #include "ostree-repo-file-enumerator.h"
 #include "ostree-gpg-verifier.h"
 
-/* XXX Only for _ostree_gpg_error_to_gio_error().  Move it elsewhere? */
-#include "ostree-gpg-verify-result-private.h"
-
 #include <locale.h>
-#include <gpgme.h>
 #include <glib/gstdio.h>
 
 /**
@@ -3065,7 +3061,7 @@ sign_data (OstreeRepo     *self,
   
   if ((err = gpgme_new (&context)) != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Unable to create gpg context: ");
       goto out;
     }
@@ -3075,7 +3071,7 @@ sign_data (OstreeRepo     *self,
   if ((err = gpgme_set_protocol (context, GPGME_PROTOCOL_OpenPGP)) !=
       GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Unable to set gpg protocol: ");
       goto out;
     }
@@ -3085,7 +3081,7 @@ sign_data (OstreeRepo     *self,
       if ((err = gpgme_ctx_set_engine_info (context, info->protocol, NULL, homedir))
           != GPG_ERR_NO_ERROR)
         {
-          _ostree_gpg_error_to_gio_error (err, error);
+          ot_gpgme_error_to_gio_error (err, error);
           g_prefix_error (error, "Unable to set gpg homedir to '%s': ",
                           homedir);
           goto out;
@@ -3103,7 +3099,7 @@ sign_data (OstreeRepo     *self,
     }
   else if (err != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Unable to lookup key ID %s: ", key_id);
       goto out;
     }
@@ -3111,7 +3107,7 @@ sign_data (OstreeRepo     *self,
   /* Add the key to the context as a signer */
   if ((err = gpgme_signers_add (context, key)) != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Error signing commit: ");
       goto out;
     }
@@ -3121,7 +3117,7 @@ sign_data (OstreeRepo     *self,
     const char *buf = g_bytes_get_data (input_data, &len);
     if ((err = gpgme_data_new_from_mem (&commit_buffer, buf, len, FALSE)) != GPG_ERR_NO_ERROR)
       {
-        _ostree_gpg_error_to_gio_error (err, error);
+        ot_gpgme_error_to_gio_error (err, error);
         g_prefix_error (error, "Failed to create buffer from commit file: ");
         goto out;
       }
@@ -3137,7 +3133,7 @@ sign_data (OstreeRepo     *self,
   
   if ((err = gpgme_data_new_from_fd (&signature_buffer, signature_fd)) != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Failed to create buffer for signature file: ");
       goto out;
     }
@@ -3145,7 +3141,7 @@ sign_data (OstreeRepo     *self,
   if ((err = gpgme_op_sign (context, commit_buffer, signature_buffer, GPGME_SIG_MODE_DETACH))
       != GPG_ERR_NO_ERROR)
     {
-      _ostree_gpg_error_to_gio_error (err, error);
+      ot_gpgme_error_to_gio_error (err, error);
       g_prefix_error (error, "Failure signing commit file: ");
       goto out;
     }
diff --git a/src/libotutil/ot-gpg-utils.c b/src/libotutil/ot-gpg-utils.c
new file mode 100644
index 0000000..d1e2a9f
--- /dev/null
+++ b/src/libotutil/ot-gpg-utils.c
@@ -0,0 +1,57 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "ot-gpg-utils.h"
+
+void
+ot_gpgme_error_to_gio_error (gpgme_error_t   gpg_error,
+                             GError        **error)
+{
+  GIOErrorEnum errcode;
+
+  /* XXX This list is incomplete.  Add cases as needed. */
+
+  switch (gpg_error)
+    {
+      /* special case - shouldn't be here */
+      case GPG_ERR_NO_ERROR:
+        g_return_if_reached ();
+
+      /* special case - abort on out-of-memory */
+      case GPG_ERR_ENOMEM:
+        g_error ("%s: %s",
+                 gpgme_strsource (gpg_error),
+                 gpgme_strerror (gpg_error));
+
+      case GPG_ERR_INV_VALUE:
+        errcode = G_IO_ERROR_INVALID_ARGUMENT;
+        break;
+
+      default:
+        errcode = G_IO_ERROR_FAILED;
+        break;
+    }
+
+  g_set_error (error, G_IO_ERROR, errcode, "%s: %s",
+               gpgme_strsource (gpg_error),
+               gpgme_strerror (gpg_error));
+}
diff --git a/src/libotutil/ot-gpg-utils.h b/src/libotutil/ot-gpg-utils.h
new file mode 100644
index 0000000..1ec9e9e
--- /dev/null
+++ b/src/libotutil/ot-gpg-utils.h
@@ -0,0 +1,30 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#pragma once
+
+#include <gpgme.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void ot_gpgme_error_to_gio_error (gpgme_error_t gpg_error, GError **error);
+
+G_END_DECLS
diff --git a/src/libotutil/otutil.h b/src/libotutil/otutil.h
index 6191602..754f925 100644
--- a/src/libotutil/otutil.h
+++ b/src/libotutil/otutil.h
@@ -46,5 +46,6 @@
 #include <ot-variant-utils.h>
 #include <ot-spawn-utils.h>
 #include <ot-checksum-utils.h>
+#include <ot-gpg-utils.h>
 
 void ot_ptrarray_add_many (GPtrArray  *a, ...) G_GNUC_NULL_TERMINATED; 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]