libotutil: Establish a place for GPG utilities
Add ot-gpg-utils.[ch] and move _ostree_gpg_error_to_gio_error() here.
This commit is contained in:
1 parent
cd93780d97
commit
ceacc57206
10 files changed
+112
-64
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user