From 0855a1296a1908016f011eb5e6552854ac53e63a Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 22 Feb 2016 18:28:08 +0100 Subject: Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New. --- lang/cpp/src/signingresult.cpp | 267 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 lang/cpp/src/signingresult.cpp (limited to 'lang/cpp/src/signingresult.cpp') diff --git a/lang/cpp/src/signingresult.cpp b/lang/cpp/src/signingresult.cpp new file mode 100644 index 00000000..f5f671b5 --- /dev/null +++ b/lang/cpp/src/signingresult.cpp @@ -0,0 +1,267 @@ +/* + signingresult.cpp - wraps a gpgme verify result + Copyright (C) 2004 Klarälvdalens Datakonsult AB + + This file is part of GPGME++. + + GPGME++ is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + GPGME++ 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 Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with GPGME++; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include "result_p.h" +#include "util.h" + +#include + +#include +#include +#include +#include +#include + +#include + +class GpgME::SigningResult::Private +{ +public: + Private(const gpgme_sign_result_t r) + { + if (!r) { + return; + } + for (gpgme_new_signature_t is = r->signatures ; is ; is = is->next) { + gpgme_new_signature_t copy = new _gpgme_new_signature(*is); + if (is->fpr) { + copy->fpr = strdup(is->fpr); + } + copy->next = 0; + created.push_back(copy); + } + for (gpgme_invalid_key_t ik = r->invalid_signers ; ik ; ik = ik->next) { + gpgme_invalid_key_t copy = new _gpgme_invalid_key(*ik); + if (ik->fpr) { + copy->fpr = strdup(ik->fpr); + } + copy->next = 0; + invalid.push_back(copy); + } + } + ~Private() + { + for (std::vector::iterator it = created.begin() ; it != created.end() ; ++it) { + std::free((*it)->fpr); + delete *it; *it = 0; + } + for (std::vector::iterator it = invalid.begin() ; it != invalid.end() ; ++it) { + std::free((*it)->fpr); + delete *it; *it = 0; + } + } + + std::vector created; + std::vector invalid; +}; + +GpgME::SigningResult::SigningResult(gpgme_ctx_t ctx, int error) + : GpgME::Result(error), d() +{ + init(ctx); +} + +GpgME::SigningResult::SigningResult(gpgme_ctx_t ctx, const Error &error) + : GpgME::Result(error), d() +{ + init(ctx); +} + +void GpgME::SigningResult::init(gpgme_ctx_t ctx) +{ + if (!ctx) { + return; + } + gpgme_sign_result_t res = gpgme_op_sign_result(ctx); + if (!res) { + return; + } + d.reset(new Private(res)); +} + +make_standard_stuff(SigningResult) + +GpgME::CreatedSignature GpgME::SigningResult::createdSignature(unsigned int idx) const +{ + return CreatedSignature(d, idx); +} + +std::vector GpgME::SigningResult::createdSignatures() const +{ + if (!d) { + return std::vector(); + } + std::vector result; + result.reserve(d->created.size()); + for (unsigned int i = 0 ; i < d->created.size() ; ++i) { + result.push_back(CreatedSignature(d, i)); + } + return result; +} + +GpgME::InvalidSigningKey GpgME::SigningResult::invalidSigningKey(unsigned int idx) const +{ + return InvalidSigningKey(d, idx); +} + +std::vector GpgME::SigningResult::invalidSigningKeys() const +{ + if (!d) { + return std::vector(); + } + std::vector result; + result.reserve(d->invalid.size()); + for (unsigned int i = 0 ; i < d->invalid.size() ; ++i) { + result.push_back(InvalidSigningKey(d, i)); + } + return result; +} + +GpgME::InvalidSigningKey::InvalidSigningKey(const boost::shared_ptr &parent, unsigned int i) + : d(parent), idx(i) +{ + +} + +GpgME::InvalidSigningKey::InvalidSigningKey() : d(), idx(0) {} + +bool GpgME::InvalidSigningKey::isNull() const +{ + return !d || idx >= d->invalid.size() ; +} + +const char *GpgME::InvalidSigningKey::fingerprint() const +{ + return isNull() ? 0 : d->invalid[idx]->fpr ; +} + +GpgME::Error GpgME::InvalidSigningKey::reason() const +{ + return Error(isNull() ? 0 : d->invalid[idx]->reason); +} + +GpgME::CreatedSignature::CreatedSignature(const boost::shared_ptr &parent, unsigned int i) + : d(parent), idx(i) +{ + +} + +GpgME::CreatedSignature::CreatedSignature() : d(), idx(0) {} + +bool GpgME::CreatedSignature::isNull() const +{ + return !d || idx >= d->created.size() ; +} + +const char *GpgME::CreatedSignature::fingerprint() const +{ + return isNull() ? 0 : d->created[idx]->fpr ; +} + +time_t GpgME::CreatedSignature::creationTime() const +{ + return static_cast(isNull() ? 0 : d->created[idx]->timestamp); +} + +GpgME::SignatureMode GpgME::CreatedSignature::mode() const +{ + if (isNull()) { + return NormalSignatureMode; + } + switch (d->created[idx]->type) { + default: + case GPGME_SIG_MODE_NORMAL: return NormalSignatureMode; + case GPGME_SIG_MODE_DETACH: return Detached; + case GPGME_SIG_MODE_CLEAR: return Clearsigned; + } +} + +unsigned int GpgME::CreatedSignature::publicKeyAlgorithm() const +{ + return isNull() ? 0 : d->created[idx]->pubkey_algo ; +} + +const char *GpgME::CreatedSignature::publicKeyAlgorithmAsString() const +{ + return gpgme_pubkey_algo_name(isNull() ? (gpgme_pubkey_algo_t)0 : d->created[idx]->pubkey_algo); +} + +unsigned int GpgME::CreatedSignature::hashAlgorithm() const +{ + return isNull() ? 0 : d->created[idx]->hash_algo ; +} + +const char *GpgME::CreatedSignature::hashAlgorithmAsString() const +{ + return gpgme_hash_algo_name(isNull() ? (gpgme_hash_algo_t)0 : d->created[idx]->hash_algo); +} + +unsigned int GpgME::CreatedSignature::signatureClass() const +{ + return isNull() ? 0 : d->created[idx]->sig_class ; +} + +std::ostream &GpgME::operator<<(std::ostream &os, const SigningResult &result) +{ + os << "GpgME::SigningResult("; + if (!result.isNull()) { + os << "\n error: " << result.error() + << "\n createdSignatures:\n"; + const std::vector cs = result.createdSignatures(); + std::copy(cs.begin(), cs.end(), + std::ostream_iterator(os, "\n")); + os << " invalidSigningKeys:\n"; + const std::vector isk = result.invalidSigningKeys(); + std::copy(isk.begin(), isk.end(), + std::ostream_iterator(os, "\n")); + } + return os << ')'; +} + +std::ostream &GpgME::operator<<(std::ostream &os, const CreatedSignature &sig) +{ + os << "GpgME::CreatedSignature("; + if (!sig.isNull()) { + os << "\n fingerprint: " << protect(sig.fingerprint()) + << "\n creationTime: " << sig.creationTime() + << "\n mode: " << sig.mode() + << "\n publicKeyAlgorithm: " << protect(sig.publicKeyAlgorithmAsString()) + << "\n hashAlgorithm: " << protect(sig.hashAlgorithmAsString()) + << "\n signatureClass: " << sig.signatureClass() + << '\n'; + } + return os << ')'; +} + +std::ostream &GpgME::operator<<(std::ostream &os, const InvalidSigningKey &key) +{ + os << "GpgME::InvalidSigningKey("; + if (!key.isNull()) { + os << "\n fingerprint: " << protect(key.fingerprint()) + << "\n reason: " << key.reason() + << '\n'; + } + return os << ')'; +} -- cgit From 433bb8e84b2d1e50b5c5b9f7f2006b60cd7d7785 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 22 Feb 2016 19:07:41 +0100 Subject: Remove feature check ifdefs * lang/cpp/src/assuanresult.cpp, lang/cpp/src/callbacks.cpp, lang/cpp/src/configuration.cpp, lang/cpp/src/context.cpp, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/editinteractor.cpp, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/engineinfo.cpp, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/global.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/importresult.cpp, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/key.cpp, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keylistresult.cpp, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/signingresult.cpp, lang/cpp/src/trustitem.cpp, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/vfsmountresult.cpp: Remove feature checks. --- lang/cpp/src/assuanresult.cpp | 8 - lang/cpp/src/callbacks.cpp | 38 ---- lang/cpp/src/configuration.cpp | 214 +--------------------- lang/cpp/src/context.cpp | 214 ---------------------- lang/cpp/src/context_glib.cpp | 9 - lang/cpp/src/context_qt.cpp | 9 - lang/cpp/src/context_vanilla.cpp | 2 - lang/cpp/src/data.cpp | 11 -- lang/cpp/src/decryptionresult.cpp | 36 ---- lang/cpp/src/defaultassuantransaction.cpp | 2 - lang/cpp/src/editinteractor.cpp | 29 +-- lang/cpp/src/encryptionresult.cpp | 2 - lang/cpp/src/engineinfo.cpp | 6 - lang/cpp/src/eventloopinteractor.cpp | 2 - lang/cpp/src/global.h | 1 - lang/cpp/src/gpgagentgetinfoassuantransaction.cpp | 2 - lang/cpp/src/importresult.cpp | 1 - lang/cpp/src/interfaces/assuantransaction.h | 2 + lang/cpp/src/key.cpp | 30 --- lang/cpp/src/keygenerationresult.cpp | 2 - lang/cpp/src/keylistresult.cpp | 2 - lang/cpp/src/scdgetinfoassuantransaction.cpp | 2 - lang/cpp/src/signingresult.cpp | 2 - lang/cpp/src/trustitem.cpp | 2 - lang/cpp/src/util.h | 35 +--- lang/cpp/src/verificationresult.cpp | 33 ---- lang/cpp/src/vfsmountresult.cpp | 8 - 27 files changed, 12 insertions(+), 692 deletions(-) (limited to 'lang/cpp/src/signingresult.cpp') diff --git a/lang/cpp/src/assuanresult.cpp b/lang/cpp/src/assuanresult.cpp index 056aefb3..3d6d0a3a 100644 --- a/lang/cpp/src/assuanresult.cpp +++ b/lang/cpp/src/assuanresult.cpp @@ -20,8 +20,6 @@ Boston, MA 02110-1301, USA. */ -#include - #include #include "result_p.h" @@ -31,7 +29,6 @@ using namespace GpgME; -#ifdef HAVE_GPGME_ASSUAN_ENGINE class AssuanResult::Private { public: @@ -45,7 +42,6 @@ public: gpgme_error_t error; }; -#endif AssuanResult::AssuanResult(gpgme_ctx_t ctx, int error) : Result(error), d() @@ -62,7 +58,6 @@ AssuanResult::AssuanResult(gpgme_ctx_t ctx, const Error &error) void AssuanResult::init(gpgme_ctx_t ctx) { (void)ctx; -#ifdef HAVE_GPGME_ASSUAN_ENGINE if (!ctx) { return; } @@ -71,18 +66,15 @@ void AssuanResult::init(gpgme_ctx_t ctx) return; } d.reset(new Private(res)); -#endif } make_standard_stuff(AssuanResult) Error AssuanResult::assuanError() const { -#ifdef HAVE_GPGME_ASSUAN_ENGINE if (d) { return Error(d->error); } -#endif return Error(); } diff --git a/lang/cpp/src/callbacks.cpp b/lang/cpp/src/callbacks.cpp index 091975d7..4b4dd806 100644 --- a/lang/cpp/src/callbacks.cpp +++ b/lang/cpp/src/callbacks.cpp @@ -20,8 +20,6 @@ Boston, MA 02110-1301, USA. */ -#include - #include "callbacks.h" #include "util.h" @@ -39,21 +37,9 @@ #include #include -#ifndef HAVE_GPGME_SSIZE_T -# define gpgme_ssize_t ssize_t -#endif - -#ifndef HAVE_GPGME_OFF_T -# define gpgme_off_t off_t -#endif - static inline gpgme_error_t make_err_from_syserror() { -#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS return gpgme_error_from_syserror(); -#else - return gpg_error_from_syserror(); -#endif } using GpgME::ProgressProvider; @@ -92,11 +78,7 @@ gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, const char size_t passphrase_length = std::strlen(passphrase); size_t written = 0; do { -#ifdef HAVE_GPGME_IO_READWRITE ssize_t now_written = gpgme_io_write(fd, passphrase + written, passphrase_length - written); -#else - ssize_t now_written = write(fd, passphrase + written, passphrase_length - written); -#endif if (now_written < 0) { err = make_err_from_syserror(); break; @@ -110,11 +92,7 @@ gpgme_error_t passphrase_callback(void *opaque, const char *uid_hint, const char wipememory(passphrase, std::strlen(passphrase)); } free(passphrase); -#ifdef HAVE_GPGME_IO_READWRITE gpgme_io_write(fd, "\n", 1); -#else - write(fd, "\n", 1); -#endif return err; } @@ -123,11 +101,7 @@ data_read_callback(void *opaque, void *buf, size_t buflen) { DataProvider *provider = static_cast(opaque); if (!provider) { -#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#else - gpg_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#endif return -1; } return (gpgme_ssize_t)provider->read(buf, buflen); @@ -138,11 +112,7 @@ data_write_callback(void *opaque, const void *buf, size_t buflen) { DataProvider *provider = static_cast(opaque); if (!provider) { -#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#else - gpg_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#endif return -1; } return (gpgme_ssize_t)provider->write(buf, buflen); @@ -153,19 +123,11 @@ data_seek_callback(void *opaque, gpgme_off_t offset, int whence) { DataProvider *provider = static_cast(opaque); if (!provider) { -#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#else - gpg_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#endif return -1; } if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { -#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS gpgme_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#else - gpg_err_set_errno(gpgme_err_code_to_errno(GPG_ERR_EINVAL)); -#endif return -1; } return provider->seek((off_t)offset, whence); diff --git a/lang/cpp/src/configuration.cpp b/lang/cpp/src/configuration.cpp index fc19020e..8a23efcf 100644 --- a/lang/cpp/src/configuration.cpp +++ b/lang/cpp/src/configuration.cpp @@ -20,8 +20,6 @@ Boston, MA 02110-1301, USA. */ -#include - #include "configuration.h" #include "error.h" #include "util.h" @@ -58,7 +56,6 @@ struct nodelete { std::vector Component::load(Error &returnedError) { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF // // 1. get a context: // @@ -101,16 +98,11 @@ std::vector Component::load(Error &returnedError) } return result; -#else - returnedError = Error(make_error(GPG_ERR_NOT_SUPPORTED)); - return std::vector(); -#endif } Error Component::save() const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF if (isNull()) { return Error(make_error(GPG_ERR_INV_ARG)); } @@ -128,41 +120,25 @@ Error Component::save() const // 2. save the config: // return Error(gpgme_op_conf_save(ctx.get(), comp.get())); -#else - return Error(make_error(GPG_ERR_NOT_SUPPORTED)); -#endif } const char *Component::name() const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF return comp ? comp->name : 0 ; -#else - return 0; -#endif } const char *Component::description() const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF return comp ? comp->description : 0 ; -#else - return 0; -#endif } const char *Component::programName() const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF return comp ? comp->program_name : 0 ; -#else - return 0; -#endif } Option Component::option(unsigned int idx) const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF gpgme_conf_opt_t opt = 0; if (comp) { opt = comp->options; @@ -173,17 +149,12 @@ Option Component::option(unsigned int idx) const } if (opt) { return Option(comp, opt); - } else { -#endif - return Option(); -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF } -#endif + return Option(); } Option Component::option(const char *name) const { -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF gpgme_conf_opt_t opt = 0; if (comp) { opt = comp->options; @@ -194,37 +165,28 @@ Option Component::option(const char *name) const } if (opt) { return Option(comp, opt); - } else { -#endif - return Option(); -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF } -#endif + return Option(); } unsigned int Component::numOptions() const { unsigned int result = 0; -#ifdef HAVE_GPGME_PROTOCOL_GPGCONF for (gpgme_conf_opt_t opt = comp ? comp->options : 0 ; opt ; opt = opt->next) { ++result; } -#endif return result; } std::vector