Blame lang/cpp/src/context.cpp

Packit Service 672cf4
/*
Packit Service 672cf4
  context.cpp - wraps a gpgme key context
Packit Service 672cf4
  Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB
Packit Service 0ef63b
                2017, 2018 Intevation GmbH
Packit Service 672cf4
Packit Service 672cf4
  This file is part of GPGME++.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is free software; you can redistribute it and/or
Packit Service 672cf4
  modify it under the terms of the GNU Library General Public
Packit Service 672cf4
  License as published by the Free Software Foundation; either
Packit Service 672cf4
  version 2 of the License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is distributed in the hope that it will be useful,
Packit Service 672cf4
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 672cf4
  GNU Library General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
  You should have received a copy of the GNU Library General Public License
Packit Service 672cf4
  along with GPGME++; see the file COPYING.LIB.  If not, write to the
Packit Service 672cf4
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit Service 672cf4
  Boston, MA 02110-1301, USA.
Packit Service 672cf4
*/
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include <context.h>
Packit Service 672cf4
#include <eventloopinteractor.h>
Packit Service 672cf4
#include <trustitem.h>
Packit Service 672cf4
#include <keylistresult.h>
Packit Service 672cf4
#include <keygenerationresult.h>
Packit Service 672cf4
#include <importresult.h>
Packit Service 672cf4
#include <decryptionresult.h>
Packit Service 672cf4
#include <verificationresult.h>
Packit Service 672cf4
#include <signingresult.h>
Packit Service 672cf4
#include <encryptionresult.h>
Packit Service 672cf4
#include <engineinfo.h>
Packit Service 672cf4
#include <editinteractor.h>
Packit Service 672cf4
#include <vfsmountresult.h>
Packit Service 672cf4
Packit Service 672cf4
#include <interfaces/assuantransaction.h>
Packit Service 672cf4
#include <defaultassuantransaction.h>
Packit Service 672cf4
Packit Service 672cf4
#include "callbacks.h"
Packit Service 672cf4
#include "data_p.h"
Packit Service 672cf4
#include "context_p.h"
Packit Service 672cf4
#include "util.h"
Packit Service 672cf4
#include "tofuinfo.h"
Packit Service 672cf4
Packit Service 672cf4
#include <gpgme.h>
Packit Service 672cf4
Packit Service 672cf4
#include <istream>
Packit Service 672cf4
#ifndef NDEBUG
Packit Service 672cf4
#include <iostream>
Packit Service 672cf4
using std::cerr;
Packit Service 672cf4
using std::endl;
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include <cassert>
Packit Service 672cf4
Packit Service 672cf4
namespace GpgME
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
static inline unsigned int xtoi_1(const char *str)
Packit Service 672cf4
{
Packit Service 672cf4
    const unsigned int ch = *str;
Packit Service 672cf4
    const unsigned int result =
Packit Service 672cf4
        ch <= '9' ? ch - '0' :
Packit Service 672cf4
        ch <= 'F' ? ch - 'A' + 10 :
Packit Service 672cf4
        /* else */  ch - 'a' + 10 ;
Packit Service 672cf4
    return result < 16 ? result : 0 ;
Packit Service 672cf4
}
Packit Service 672cf4
static inline int xtoi_2(const char *str)
Packit Service 672cf4
{
Packit Service 672cf4
    return xtoi_1(str) * 16U + xtoi_1(str + 1);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static void percent_unescape(std::string &s, bool plus2space)
Packit Service 672cf4
{
Packit Service 672cf4
    std::string::iterator src = s.begin(), dest = s.begin(), end = s.end();
Packit Service 672cf4
    while (src != end) {
Packit Service 672cf4
        if (*src == '%' && end - src > 2) {
Packit Service 672cf4
            *dest++ = xtoi_2(&*++src);
Packit Service 672cf4
            src += 2;
Packit Service 672cf4
        } else if (*src == '+' && plus2space) {
Packit Service 672cf4
            *dest++ = ' ';
Packit Service 672cf4
            ++src;
Packit Service 672cf4
        } else {
Packit Service 672cf4
            *dest++ = *src++;
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
    s.erase(dest, end);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void initializeLibrary()
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_check_version(nullptr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error initializeLibrary(int)
Packit Service 672cf4
{
Packit Service 672cf4
    if (gpgme_check_version(GPGME_VERSION)) {
Packit Service 672cf4
        return Error();
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return Error::fromCode(GPG_ERR_USER_1);
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static void format_error(gpgme_error_t err, std::string &str)
Packit Service 672cf4
{
Packit Service 672cf4
    char buffer[ 1024 ];
Packit Service 672cf4
    gpgme_strerror_r(err, buffer, sizeof buffer);
Packit Service 672cf4
    buffer[ sizeof buffer - 1 ] = '\0';
Packit Service 672cf4
    str = buffer;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *Error::source() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_strsource((gpgme_error_t)mErr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *Error::asString() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (mMessage.empty()) {
Packit Service 672cf4
        format_error(static_cast<gpgme_error_t>(mErr), mMessage);
Packit Service 672cf4
    }
Packit Service 672cf4
    return mMessage.c_str();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int Error::code() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_err_code(mErr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int Error::sourceID() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_err_source(mErr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
bool Error::isCanceled() const
Packit Service 672cf4
{
Packit Service 672cf4
    return code() == GPG_ERR_CANCELED;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int Error::toErrno() const
Packit Service 672cf4
{
Packit Service 672cf4
//#ifdef HAVE_GPGME_GPG_ERROR_WRAPPERS
Packit Service 672cf4
    return gpgme_err_code_to_errno(static_cast<gpgme_err_code_t>(code()));
Packit Service 672cf4
//#else
Packit Service 672cf4
//    return gpg_err_code_to_errno( static_cast<gpg_err_code_t>( code() ) );
Packit Service 672cf4
//#endif
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
bool Error::hasSystemError()
Packit Service 672cf4
{
Packit Service 0ef63b
    return gpgme_err_code_from_syserror() != GPG_ERR_MISSING_ERRNO ;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
void Error::setSystemError(gpg_err_code_t err)
Packit Service 672cf4
{
Packit Service 672cf4
    setErrno(gpgme_err_code_to_errno(err));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
void Error::setErrno(int err)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_err_set_errno(err);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
Error Error::fromSystemError(unsigned int src)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), gpgme_err_code_from_syserror()));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
Error Error::fromErrno(int err, unsigned int src)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), gpgme_err_code_from_errno(err)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
// static
Packit Service 672cf4
Error Error::fromCode(unsigned int err, unsigned int src)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_err_make(static_cast<gpgme_err_source_t>(src), static_cast<gpgme_err_code_t>(err)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, const Error &err)
Packit Service 672cf4
{
Packit Service 672cf4
    return os << "GpgME::Error(" << err.encodedError() << " (" << err.asString() << "))";
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Context::Context(gpgme_ctx_t ctx) : d(new Private(ctx))
Packit Service 672cf4
{
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Context::~Context()
Packit Service 672cf4
{
Packit Service 672cf4
    delete d;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Context *Context::createForProtocol(Protocol proto)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_ctx_t ctx = nullptr;
Packit Service 672cf4
    if (gpgme_new(&ctx) != 0) {
Packit Service 0ef63b
        return nullptr;
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    switch (proto) {
Packit Service 672cf4
    case OpenPGP:
Packit Service 672cf4
        if (gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP) != 0) {
Packit Service 672cf4
            gpgme_release(ctx);
Packit Service 0ef63b
            return nullptr;
Packit Service 672cf4
        }
Packit Service 672cf4
        break;
Packit Service 672cf4
    case CMS:
Packit Service 672cf4
        if (gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS) != 0) {
Packit Service 672cf4
            gpgme_release(ctx);
Packit Service 0ef63b
            return nullptr;
Packit Service 672cf4
        }
Packit Service 672cf4
        break;
Packit Service 672cf4
    default:
Packit Service 0ef63b
        return nullptr;
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    return new Context(ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 0ef63b
std::unique_ptr<Context> Context::create(Protocol proto)
Packit Service 0ef63b
{
Packit Service 0ef63b
  return std::unique_ptr <Context> (createForProtocol(proto));
Packit Service 0ef63b
}
Packit Service 0ef63b
Packit Service 672cf4
std::unique_ptr<Context> Context::createForEngine(Engine eng, Error *error)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_ctx_t ctx = nullptr;
Packit Service 672cf4
    if (const gpgme_error_t err = gpgme_new(&ctx)) {
Packit Service 672cf4
        if (error) {
Packit Service 672cf4
            *error = Error(err);
Packit Service 672cf4
        }
Packit Service 672cf4
        return std::unique_ptr<Context>();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    switch (eng) {
Packit Service 672cf4
    case AssuanEngine:
Packit Service 672cf4
        if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_ASSUAN)) {
Packit Service 672cf4
            gpgme_release(ctx);
Packit Service 672cf4
            if (error) {
Packit Service 672cf4
                *error = Error(err);
Packit Service 672cf4
            }
Packit Service 672cf4
            return std::unique_ptr<Context>();
Packit Service 672cf4
        }
Packit Service 672cf4
        break;
Packit Service 672cf4
    case G13Engine:
Packit Service 672cf4
        if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_G13)) {
Packit Service 672cf4
            gpgme_release(ctx);
Packit Service 672cf4
            if (error) {
Packit Service 672cf4
                *error = Error(err);
Packit Service 672cf4
            }
Packit Service 672cf4
            return std::unique_ptr<Context>();
Packit Service 672cf4
        }
Packit Service 672cf4
        break;
Packit Service 672cf4
    case SpawnEngine:
Packit Service 672cf4
        if (const gpgme_error_t err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_SPAWN)) {
Packit Service 672cf4
            gpgme_release(ctx);
Packit Service 672cf4
            if (error) {
Packit Service 672cf4
                *error = Error(err);
Packit Service 672cf4
            }
Packit Service 672cf4
            return std::unique_ptr<Context>();
Packit Service 672cf4
        }
Packit Service 672cf4
        break;
Packit Service 672cf4
    default:
Packit Service 672cf4
        if (error) {
Packit Service 672cf4
            *error = Error::fromCode(GPG_ERR_INV_ARG);
Packit Service 672cf4
        }
Packit Service 672cf4
        return std::unique_ptr<Context>();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    if (error) {
Packit Service 672cf4
        *error = Error();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    return std::unique_ptr<Context>(new Context(ctx));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setDecryptionFlags(DecryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->decryptFlags = flags;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
// Context::Private
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
Packit Service 672cf4
Context::Private::Private(gpgme_ctx_t c)
Packit Service 672cf4
    : ctx(c),
Packit Service 0ef63b
      iocbs(nullptr),
Packit Service 672cf4
      lastop(None),
Packit Service 672cf4
      lasterr(GPG_ERR_NO_ERROR),
Packit Service 672cf4
      lastAssuanInquireData(Data::null),
Packit Service 672cf4
      lastAssuanTransaction(),
Packit Service 672cf4
      lastEditInteractor(),
Packit Service 672cf4
      lastCardEditInteractor(),
Packit Service 672cf4
      decryptFlags(DecryptNone)
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Context::Private::~Private()
Packit Service 672cf4
{
Packit Service 672cf4
    if (ctx) {
Packit Service 672cf4
        gpgme_release(ctx);
Packit Service 672cf4
    }
Packit Service 0ef63b
    ctx = nullptr;
Packit Service 672cf4
    delete iocbs;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
// Context attributes:
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
Packit Service 672cf4
Protocol Context::protocol() const
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_protocol_t p = gpgme_get_protocol(d->ctx);
Packit Service 672cf4
    switch (p) {
Packit Service 672cf4
    case GPGME_PROTOCOL_OpenPGP: return OpenPGP;
Packit Service 672cf4
    case GPGME_PROTOCOL_CMS:     return CMS;
Packit Service 672cf4
    default:                     return UnknownProtocol;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setArmor(bool useArmor)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_set_armor(d->ctx, int(useArmor));
Packit Service 672cf4
}
Packit Service 672cf4
bool Context::armor() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_armor(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setTextMode(bool useTextMode)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_set_textmode(d->ctx, int(useTextMode));
Packit Service 672cf4
}
Packit Service 672cf4
bool Context::textMode() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_textmode(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setOffline(bool useOfflineMode)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_set_offline(d->ctx, int(useOfflineMode));
Packit Service 672cf4
}
Packit Service 672cf4
bool Context::offline() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_offline(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setIncludeCertificates(int which)
Packit Service 672cf4
{
Packit Service 672cf4
    if (which == DefaultCertificates) {
Packit Service 672cf4
        which = GPGME_INCLUDE_CERTS_DEFAULT;
Packit Service 672cf4
    }
Packit Service 672cf4
    gpgme_set_include_certs(d->ctx, which);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
int Context::includeCertificates() const
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_include_certs(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setKeyListMode(unsigned int mode)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_set_keylist_mode(d->ctx, add_to_gpgme_keylist_mode_t(0, mode));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::addKeyListMode(unsigned int mode)
Packit Service 672cf4
{
Packit Service 672cf4
    const unsigned int cur = gpgme_get_keylist_mode(d->ctx);
Packit Service 672cf4
    gpgme_set_keylist_mode(d->ctx, add_to_gpgme_keylist_mode_t(cur, mode));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
unsigned int Context::keyListMode() const
Packit Service 672cf4
{
Packit Service 672cf4
    return convert_from_gpgme_keylist_mode_t(gpgme_get_keylist_mode(d->ctx));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setProgressProvider(ProgressProvider *provider)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_set_progress_cb(d->ctx, provider ? &progress_callback : nullptr, provider);
Packit Service 672cf4
}
Packit Service 672cf4
ProgressProvider *Context::progressProvider() const
Packit Service 672cf4
{
Packit Service 0ef63b
    void *pp = nullptr;
Packit Service 672cf4
    gpgme_progress_cb_t pcb = &progress_callback;
Packit Service 672cf4
    gpgme_get_progress_cb(d->ctx, &pcb, &pp;;
Packit Service 672cf4
    return static_cast<ProgressProvider *>(pp);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setPassphraseProvider(PassphraseProvider *provider)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_set_passphrase_cb(d->ctx, provider ? &passphrase_callback : nullptr, provider);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
PassphraseProvider *Context::passphraseProvider() const
Packit Service 672cf4
{
Packit Service 0ef63b
    void *pp = nullptr;
Packit Service 672cf4
    gpgme_passphrase_cb_t pcb = &passphrase_callback;
Packit Service 672cf4
    gpgme_get_passphrase_cb(d->ctx, &pcb, &pp;;
Packit Service 672cf4
    return static_cast<PassphraseProvider *>(pp);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::setManagedByEventLoopInteractor(bool manage)
Packit Service 672cf4
{
Packit Service 672cf4
    if (!EventLoopInteractor::instance()) {
Packit Service 672cf4
#ifndef NDEBUG
Packit Service 672cf4
        cerr << "Context::setManagedByEventLoopInteractor(): "
Packit Service 672cf4
             "You must create an instance of EventLoopInteractor "
Packit Service 672cf4
             "before using anything that needs one." << endl;
Packit Service 672cf4
#endif
Packit Service 672cf4
        return;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (manage) {
Packit Service 672cf4
        EventLoopInteractor::instance()->manage(this);
Packit Service 672cf4
    } else {
Packit Service 672cf4
        EventLoopInteractor::instance()->unmanage(this);
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
bool Context::managedByEventLoopInteractor() const
Packit Service 672cf4
{
Packit Service 0ef63b
    return d->iocbs != nullptr;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::installIOCallbacks(gpgme_io_cbs *iocbs)
Packit Service 672cf4
{
Packit Service 672cf4
    if (!iocbs) {
Packit Service 672cf4
        uninstallIOCallbacks();
Packit Service 672cf4
        return;
Packit Service 672cf4
    }
Packit Service 672cf4
    gpgme_set_io_cbs(d->ctx, iocbs);
Packit Service 672cf4
    delete d->iocbs; d->iocbs = iocbs;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::uninstallIOCallbacks()
Packit Service 672cf4
{
Packit Service 0ef63b
    static gpgme_io_cbs noiocbs = { nullptr, nullptr, nullptr, nullptr, nullptr };
Packit Service 672cf4
    // io.add == 0 means disable io callbacks:
Packit Service 672cf4
    gpgme_set_io_cbs(d->ctx, &noiocbs);
Packit Service 0ef63b
    delete d->iocbs; d->iocbs = nullptr;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setLocale(int cat, const char *val)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_set_locale(d->ctx, cat, val));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
EngineInfo Context::engineInfo() const
Packit Service 672cf4
{
Packit Service 672cf4
    return EngineInfo(gpgme_ctx_get_engine_info(d->ctx));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setEngineFileName(const char *filename)
Packit Service 672cf4
{
Packit Service 672cf4
    const char *const home_dir = engineInfo().homeDirectory();
Packit Service 672cf4
    return Error(gpgme_ctx_set_engine_info(d->ctx, gpgme_get_protocol(d->ctx), filename, home_dir));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setEngineHomeDirectory(const char *home_dir)
Packit Service 672cf4
{
Packit Service 672cf4
    const char *const filename = engineInfo().fileName();
Packit Service 672cf4
    return Error(gpgme_ctx_set_engine_info(d->ctx, gpgme_get_protocol(d->ctx), filename, home_dir));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setSender (const char *sender)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_set_sender(d->ctx, sender));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *Context::getSender ()
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_sender(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
// Key Management
Packit Service 672cf4
//
Packit Service 672cf4
//
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyListing(const char *pattern, bool secretOnly)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyList;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_keylist_start(d->ctx, pattern, int(secretOnly)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyListing(const char *patterns[], bool secretOnly)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyList;
Packit Service 672cf4
#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN
Packit Service 672cf4
    if (!patterns || !patterns[0] || !patterns[1]) {
Packit Service 672cf4
        // max. one pattern -> use the non-ext version
Packit Service 0ef63b
        return startKeyListing(patterns ? patterns[0] : nullptr, secretOnly);
Packit Service 672cf4
    }
Packit Service 672cf4
#endif
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_keylist_ext_start(d->ctx, patterns, int(secretOnly), 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Key Context::nextKey(GpgME::Error &e)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyList;
Packit Service 0ef63b
    gpgme_key_t key = nullptr;
Packit Service 672cf4
    e = Error(d->lasterr = gpgme_op_keylist_next(d->ctx, &key));
Packit Service 672cf4
    return Key(key, false);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
KeyListResult Context::endKeyListing()
Packit Service 672cf4
{
Packit Service 672cf4
    d->lasterr = gpgme_op_keylist_end(d->ctx);
Packit Service 672cf4
    return keyListResult();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
KeyListResult Context::keyListResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    return KeyListResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Key Context::key(const char *fingerprint, GpgME::Error &e , bool secret /*, bool forceUpdate*/)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyList;
Packit Service 0ef63b
    gpgme_key_t key = nullptr;
Packit Service 672cf4
    e = Error(d->lasterr = gpgme_get_key(d->ctx, fingerprint, &key, int(secret)/*, int( forceUpdate )*/));
Packit Service 672cf4
    return Key(key, false);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
KeyGenerationResult Context::generateKey(const char *parameters, Data &pubKey)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyGen;
Packit Service 672cf4
    Data::Private *const dp = pubKey.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_genkey(d->ctx, parameters, dp ? dp->data : nullptr, nullptr);
Packit Service 672cf4
    return KeyGenerationResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyGeneration(const char *parameters, Data &pubKey)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::KeyGen;
Packit Service 672cf4
    Data::Private *const dp = pubKey.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_genkey_start(d->ctx, parameters, dp ? dp->data : nullptr, nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
KeyGenerationResult Context::keyGenerationResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::KeyGen) {
Packit Service 672cf4
        return KeyGenerationResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return KeyGenerationResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::exportPublicKeys(const char *pattern, Data &keyData)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Export;
Packit Service 672cf4
    Data::Private *const dp = keyData.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_export(d->ctx, pattern, 0, dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::exportPublicKeys(const char *patterns[], Data &keyData)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Export;
Packit Service 672cf4
#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN
Packit Service 672cf4
    if (!patterns || !patterns[0] || !patterns[1]) {
Packit Service 672cf4
        // max. one pattern -> use the non-ext version
Packit Service 0ef63b
        return exportPublicKeys(patterns ? patterns[0] : nullptr, keyData);
Packit Service 672cf4
    }
Packit Service 672cf4
#endif
Packit Service 672cf4
    Data::Private *const dp = keyData.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_export_ext(d->ctx, patterns, 0, dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startPublicKeyExport(const char *pattern, Data &keyData)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Export;
Packit Service 672cf4
    Data::Private *const dp = keyData.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_export_start(d->ctx, pattern, 0, dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startPublicKeyExport(const char *patterns[], Data &keyData)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Export;
Packit Service 672cf4
#ifndef HAVE_GPGME_EXT_KEYLIST_MODE_EXTERNAL_NONBROKEN
Packit Service 672cf4
    if (!patterns || !patterns[0] || !patterns[1]) {
Packit Service 672cf4
        // max. one pattern -> use the non-ext version
Packit Service 0ef63b
        return startPublicKeyExport(patterns ? patterns[0] : nullptr, keyData);
Packit Service 672cf4
    }
Packit Service 672cf4
#endif
Packit Service 672cf4
    Data::Private *const dp = keyData.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_export_ext_start(d->ctx, patterns, 0, dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
ImportResult Context::importKeys(const Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Import;
Packit Service 672cf4
    const Data::Private *const dp = data.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_import(d->ctx, dp ? dp->data : nullptr);
Packit Service 672cf4
    return ImportResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
ImportResult Context::importKeys(const std::vector<Key> &kk)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Import;
Packit Service 672cf4
    d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED);
Packit Service 672cf4
Packit Service 672cf4
    bool shouldHaveResult = false;
Packit Service 672cf4
    gpgme_key_t * const keys = new gpgme_key_t[ kk.size() + 1 ];
Packit Service 672cf4
    gpgme_key_t *keys_it = &keys[0];
Packit Service 672cf4
    for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) {
Packit Service 672cf4
        if (it->impl()) {
Packit Service 672cf4
            *keys_it++ = it->impl();
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 0ef63b
    *keys_it++ = nullptr;
Packit Service 672cf4
    d->lasterr = gpgme_op_import_keys(d->ctx, keys);
Packit Service 672cf4
    shouldHaveResult = true;
Packit Service 672cf4
    if ((gpgme_err_code(d->lasterr) == GPG_ERR_NOT_IMPLEMENTED ||
Packit Service 672cf4
            gpgme_err_code(d->lasterr) == GPG_ERR_NOT_SUPPORTED) &&
Packit Service 672cf4
            protocol() == CMS) {
Packit Service 672cf4
        // ok, try the workaround (export+import):
Packit Service 672cf4
        std::vector<const char *> fprs;
Packit Service 672cf4
        for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) {
Packit Service 672cf4
            if (const char *fpr = it->primaryFingerprint()) {
Packit Service 672cf4
                if (*fpr) {
Packit Service 672cf4
                    fprs.push_back(fpr);
Packit Service 672cf4
                }
Packit Service 672cf4
            } else if (const char *keyid = it->keyID()) {
Packit Service 672cf4
                if (*keyid) {
Packit Service 672cf4
                    fprs.push_back(keyid);
Packit Service 672cf4
                }
Packit Service 672cf4
            }
Packit Service 672cf4
        }
Packit Service 0ef63b
        fprs.push_back(nullptr);
Packit Service 672cf4
        Data data;
Packit Service 672cf4
        Data::Private *const dp = data.impl();
Packit Service 672cf4
        const gpgme_keylist_mode_t oldMode = gpgme_get_keylist_mode(d->ctx);
Packit Service 672cf4
        gpgme_set_keylist_mode(d->ctx, GPGME_KEYLIST_MODE_EXTERN);
Packit Service 0ef63b
        d->lasterr = gpgme_op_export_ext(d->ctx, &fprs[0], 0, dp ? dp->data : nullptr);
Packit Service 672cf4
        gpgme_set_keylist_mode(d->ctx, oldMode);
Packit Service 672cf4
        if (!d->lasterr) {
Packit Service 672cf4
            data.seek(0, SEEK_SET);
Packit Service 0ef63b
            d->lasterr = gpgme_op_import(d->ctx, dp ? dp->data : nullptr);
Packit Service 672cf4
            shouldHaveResult = true;
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
    delete[] keys;
Packit Service 672cf4
    if (shouldHaveResult) {
Packit Service 672cf4
        return ImportResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return ImportResult(Error(d->lasterr));
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyImport(const Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Import;
Packit Service 672cf4
    const Data::Private *const dp = data.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_import_start(d->ctx, dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyImport(const std::vector<Key> &kk)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Import;
Packit Service 672cf4
    gpgme_key_t * const keys = new gpgme_key_t[ kk.size() + 1 ];
Packit Service 672cf4
    gpgme_key_t *keys_it = &keys[0];
Packit Service 672cf4
    for (std::vector<Key>::const_iterator it = kk.begin(), end = kk.end() ; it != end ; ++it) {
Packit Service 672cf4
        if (it->impl()) {
Packit Service 672cf4
            *keys_it++ = it->impl();
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 0ef63b
    *keys_it++ = nullptr;
Packit Service 672cf4
    Error err = Error(d->lasterr = gpgme_op_import_keys_start(d->ctx, keys));
Packit Service 672cf4
    delete[] keys;
Packit Service 672cf4
    return err;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
ImportResult Context::importResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::Import) {
Packit Service 672cf4
        return ImportResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return ImportResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::deleteKey(const Key &key, bool allowSecretKeyDeletion)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Delete;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_delete(d->ctx, key.impl(), int(allowSecretKeyDeletion)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startKeyDeletion(const Key &key, bool allowSecretKeyDeletion)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Delete;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_delete_start(d->ctx, key.impl(), int(allowSecretKeyDeletion)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::passwd(const Key &key)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Passwd;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_passwd(d->ctx, key.impl(), 0U));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startPasswd(const Key &key)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Passwd;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_passwd_start(d->ctx, key.impl(), 0U));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
#pragma GCC diagnostic push
Packit Service 672cf4
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Packit Service 672cf4
Packit Service 672cf4
Error Context::edit(const Key &key, std::unique_ptr<EditInteractor> func, Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Edit;
Packit Service 672cf4
    d->lastEditInteractor = std::move(func);
Packit Service 672cf4
    Data::Private *const dp = data.impl();
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_edit(d->ctx, key.impl(),
Packit Service 0ef63b
                                            d->lastEditInteractor.get() ? edit_interactor_callback : nullptr,
Packit Service 0ef63b
                                            d->lastEditInteractor.get() ? d->lastEditInteractor->d : nullptr,
Packit Service 0ef63b
                                            dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
Error Context::startEditing(const Key &key, std::unique_ptr<EditInteractor> func, Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Edit;
Packit Service 672cf4
    d->lastEditInteractor = std::move(func);
Packit Service 672cf4
    Data::Private *const dp = data.impl();
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_edit_start(d->ctx, key.impl(),
Packit Service 0ef63b
                              d->lastEditInteractor.get() ? edit_interactor_callback : nullptr,
Packit Service 0ef63b
                              d->lastEditInteractor.get() ? d->lastEditInteractor->d : nullptr,
Packit Service 0ef63b
                              dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
EditInteractor *Context::lastEditInteractor() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d->lastEditInteractor.get();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::unique_ptr<EditInteractor> Context::takeLastEditInteractor()
Packit Service 672cf4
{
Packit Service 672cf4
    return std::move(d->lastEditInteractor);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
Error Context::cardEdit(const Key &key, std::unique_ptr<EditInteractor> func, Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::CardEdit;
Packit Service 672cf4
    d->lastCardEditInteractor = std::move(func);
Packit Service 672cf4
    Data::Private *const dp = data.impl();
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_card_edit(d->ctx, key.impl(),
Packit Service 0ef63b
                              d->lastCardEditInteractor.get() ? edit_interactor_callback : nullptr,
Packit Service 0ef63b
                              d->lastCardEditInteractor.get() ? d->lastCardEditInteractor->d : nullptr,
Packit Service 0ef63b
                              dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCardEditing(const Key &key, std::unique_ptr<EditInteractor> func, Data &data)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::CardEdit;
Packit Service 672cf4
    d->lastCardEditInteractor = std::move(func);
Packit Service 672cf4
    Data::Private *const dp = data.impl();
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_card_edit_start(d->ctx, key.impl(),
Packit Service 0ef63b
                              d->lastCardEditInteractor.get() ? edit_interactor_callback : nullptr,
Packit Service 0ef63b
                              d->lastCardEditInteractor.get() ? d->lastCardEditInteractor->d : nullptr,
Packit Service 0ef63b
                              dp ? dp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
#pragma GCC diagnostic pop
Packit Service 672cf4
Packit Service 672cf4
EditInteractor *Context::lastCardEditInteractor() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d->lastCardEditInteractor.get();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::unique_ptr<EditInteractor> Context::takeLastCardEditInteractor()
Packit Service 672cf4
{
Packit Service 672cf4
    return std::move(d->lastCardEditInteractor);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startTrustItemListing(const char *pattern, int maxLevel)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::TrustList;
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_trustlist_start(d->ctx, pattern, maxLevel));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
TrustItem Context::nextTrustItem(Error &e)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_trust_item_t ti = nullptr;
Packit Service 672cf4
    e = Error(d->lasterr = gpgme_op_trustlist_next(d->ctx, &ti);;
Packit Service 672cf4
    return TrustItem(ti);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::endTrustItemListing()
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_trustlist_end(d->ctx));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_error_t assuan_transaction_data_callback(void *opaque, const void *data, size_t datalen)
Packit Service 672cf4
{
Packit Service 672cf4
    assert(opaque);
Packit Service 672cf4
    AssuanTransaction *t = static_cast<AssuanTransaction *>(opaque);
Packit Service 672cf4
    return t->data(static_cast<const char *>(data), datalen).encodedError();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_error_t assuan_transaction_inquire_callback(void *opaque, const char *name, const char *args, gpgme_data_t *r_data)
Packit Service 672cf4
{
Packit Service 672cf4
    assert(opaque);
Packit Service 672cf4
    Context::Private *p = static_cast<Context::Private *>(opaque);
Packit Service 672cf4
    AssuanTransaction *t = p->lastAssuanTransaction.get();
Packit Service 672cf4
    assert(t);
Packit Service 672cf4
    Error err;
Packit Service 672cf4
    if (name) {
Packit Service 672cf4
        p->lastAssuanInquireData = t->inquire(name, args, err);
Packit Service 672cf4
    } else {
Packit Service 672cf4
        p->lastAssuanInquireData = Data::null;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (!p->lastAssuanInquireData.isNull()) {
Packit Service 672cf4
        *r_data = p->lastAssuanInquireData.impl()->data;
Packit Service 672cf4
    }
Packit Service 672cf4
    return err.encodedError();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_error_t assuan_transaction_status_callback(void *opaque, const char *status, const char *args)
Packit Service 672cf4
{
Packit Service 672cf4
    assert(opaque);
Packit Service 672cf4
    AssuanTransaction *t = static_cast<AssuanTransaction *>(opaque);
Packit Service 672cf4
    std::string a = args;
Packit Service 672cf4
    percent_unescape(a, true);   // ### why doesn't gpgme do this??
Packit Service 672cf4
    return t->status(status, a.c_str()).encodedError();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::assuanTransact(const char *command)
Packit Service 672cf4
{
Packit Service 672cf4
    return assuanTransact(command, std::unique_ptr<AssuanTransaction>(new DefaultAssuanTransaction));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::assuanTransact(const char *command, std::unique_ptr<AssuanTransaction> transaction)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_error_t err, operr;
Packit Service 672cf4
Packit Service 672cf4
    d->lastop = Private::AssuanTransact;
Packit Service 672cf4
    d->lastAssuanTransaction = std::move(transaction);
Packit Service 672cf4
    if (!d->lastAssuanTransaction.get()) {
Packit Service 672cf4
        return Error(d->lasterr = make_error(GPG_ERR_INV_ARG));
Packit Service 672cf4
    }
Packit Service 672cf4
    err = gpgme_op_assuan_transact_ext
Packit Service 672cf4
      (d->ctx,
Packit Service 672cf4
       command,
Packit Service 672cf4
       assuan_transaction_data_callback,
Packit Service 672cf4
       d->lastAssuanTransaction.get(),
Packit Service 672cf4
       assuan_transaction_inquire_callback,
Packit Service 672cf4
       d,
Packit Service 672cf4
       assuan_transaction_status_callback,
Packit Service 672cf4
       d->lastAssuanTransaction.get(),
Packit Service 672cf4
       &operr;;
Packit Service 672cf4
Packit Service 672cf4
    if (!err)
Packit Service 672cf4
      err = operr;
Packit Service 672cf4
    d->lasterr = err;
Packit Service 672cf4
Packit Service 672cf4
    return Error(d->lasterr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startAssuanTransaction(const char *command)
Packit Service 672cf4
{
Packit Service 672cf4
    return startAssuanTransaction(command, std::unique_ptr<AssuanTransaction>(new DefaultAssuanTransaction));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startAssuanTransaction(const char *command, std::unique_ptr<AssuanTransaction> transaction)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_error_t err;
Packit Service 672cf4
Packit Service 672cf4
    d->lastop = Private::AssuanTransact;
Packit Service 672cf4
    d->lastAssuanTransaction = std::move(transaction);
Packit Service 672cf4
    if (!d->lastAssuanTransaction.get()) {
Packit Service 672cf4
        return Error(d->lasterr = make_error(GPG_ERR_INV_ARG));
Packit Service 672cf4
    }
Packit Service 672cf4
    err = gpgme_op_assuan_transact_start
Packit Service 672cf4
      (d->ctx,
Packit Service 672cf4
       command,
Packit Service 672cf4
       assuan_transaction_data_callback,
Packit Service 672cf4
       d->lastAssuanTransaction.get(),
Packit Service 672cf4
       assuan_transaction_inquire_callback,
Packit Service 672cf4
       d,
Packit Service 672cf4
       assuan_transaction_status_callback,
Packit Service 672cf4
       d->lastAssuanTransaction.get());
Packit Service 672cf4
Packit Service 672cf4
    d->lasterr = err;
Packit Service 672cf4
Packit Service 672cf4
    return Error(d->lasterr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
AssuanTransaction *Context::lastAssuanTransaction() const
Packit Service 672cf4
{
Packit Service 672cf4
    return d->lastAssuanTransaction.get();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::unique_ptr<AssuanTransaction> Context::takeLastAssuanTransaction()
Packit Service 672cf4
{
Packit Service 672cf4
    return std::move(d->lastAssuanTransaction);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText, const DecryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Decrypt;
Packit Service 672cf4
    const Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags), cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr);
Packit Service 672cf4
    return DecryptionResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
DecryptionResult Context::decrypt(const Data &cipherText, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    return decrypt(cipherText, plainText, DecryptNone);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startDecryption(const Data &cipherText, Data &plainText, const DecryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Decrypt;
Packit Service 672cf4
    const Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags),
Packit Service 0ef63b
                 cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startDecryption(const Data &cipherText, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    return startDecryption(cipherText, plainText, DecryptNone);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
DecryptionResult Context::decryptionResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::Decrypt) {
Packit Service 672cf4
        return DecryptionResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return DecryptionResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
VerificationResult Context::verifyDetachedSignature(const Data &signature, const Data &signedText)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Verify;
Packit Service 672cf4
    const Data::Private *const sdp = signature.impl();
Packit Service 672cf4
    const Data::Private *const tdp = signedText.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_verify(d->ctx, sdp ? sdp->data : nullptr, tdp ? tdp->data : nullptr, nullptr);
Packit Service 672cf4
    return VerificationResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
VerificationResult Context::verifyOpaqueSignature(const Data &signedData, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Verify;
Packit Service 672cf4
    const Data::Private *const sdp = signedData.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_verify(d->ctx, sdp ? sdp->data : nullptr, nullptr, pdp ? pdp->data : nullptr);
Packit Service 672cf4
    return VerificationResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startDetachedSignatureVerification(const Data &signature, const Data &signedText)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Verify;
Packit Service 672cf4
    const Data::Private *const sdp = signature.impl();
Packit Service 672cf4
    const Data::Private *const tdp = signedText.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_verify_start(d->ctx, sdp ? sdp->data : nullptr, tdp ? tdp->data : nullptr, nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startOpaqueSignatureVerification(const Data &signedData, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Verify;
Packit Service 672cf4
    const Data::Private *const sdp = signedData.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_verify_start(d->ctx, sdp ? sdp->data : nullptr, nullptr, pdp ? pdp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
VerificationResult Context::verificationResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::Verify) {
Packit Service 672cf4
        return VerificationResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return VerificationResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::pair<DecryptionResult, VerificationResult> Context::decryptAndVerify(const Data &cipherText, Data &plainText, DecryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::DecryptAndVerify;
Packit Service 672cf4
    const Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    d->lasterr = gpgme_op_decrypt_ext(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags | DecryptVerify),
Packit Service 0ef63b
                                      cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr);
Packit Service 672cf4
    return std::make_pair(DecryptionResult(d->ctx, Error(d->lasterr)),
Packit Service 672cf4
                          VerificationResult(d->ctx, Error(d->lasterr)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::pair<DecryptionResult, VerificationResult> Context::decryptAndVerify(const Data &cipherText, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    return decryptAndVerify(cipherText, plainText, DecryptNone);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText, DecryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::DecryptAndVerify;
Packit Service 672cf4
    const Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    Data::Private *const pdp = plainText.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_decrypt_ext_start(d->ctx, static_cast<gpgme_decrypt_flags_t> (d->decryptFlags | flags | DecryptVerify), cdp ? cdp->data : nullptr, pdp ? pdp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCombinedDecryptionAndVerification(const Data &cipherText, Data &plainText)
Packit Service 672cf4
{
Packit Service 672cf4
    return startCombinedDecryptionAndVerification(cipherText, plainText, DecryptNone);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
unsigned int to_auditlog_flags(unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    unsigned int result = 0;
Packit Service 672cf4
    if (flags & Context::HtmlAuditLog) {
Packit Service 672cf4
        result |= GPGME_AUDITLOG_HTML;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::AuditLogWithHelp) {
Packit Service 672cf4
        result |= GPGME_AUDITLOG_WITH_HELP;
Packit Service 672cf4
    }
Packit Service 0ef63b
    if (flags & Context::DiagnosticAuditLog) {
Packit Service 0ef63b
        result |= GPGME_AUDITLOG_DIAG;
Packit Service 0ef63b
    }
Packit Service 672cf4
    return result;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startGetAuditLog(Data &output, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::GetAuditLog;
Packit Service 672cf4
    Data::Private *const odp = output.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_getauditlog_start(d->ctx, odp ? odp->data : nullptr, to_auditlog_flags(flags)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::getAuditLog(Data &output, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::GetAuditLog;
Packit Service 672cf4
    Data::Private *const odp = output.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_getauditlog(d->ctx, odp ? odp->data : nullptr, to_auditlog_flags(flags)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::clearSigningKeys()
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_signers_clear(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::addSigningKey(const Key &key)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_signers_add(d->ctx, key.impl()));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Key Context::signingKey(unsigned int idx) const
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_key_t key = gpgme_signers_enum(d->ctx, idx);
Packit Service 672cf4
    return Key(key, false);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::vector<Key> Context::signingKeys() const
Packit Service 672cf4
{
Packit Service 672cf4
    std::vector<Key> result;
Packit Service 0ef63b
    gpgme_key_t key = nullptr;
Packit Service 672cf4
    for (unsigned int i = 0 ; (key = gpgme_signers_enum(d->ctx, i)) ; ++i) {
Packit Service 672cf4
        result.push_back(Key(key, false));
Packit Service 672cf4
    }
Packit Service 672cf4
    return result;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void Context::clearSignatureNotations()
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_sig_notation_clear(d->ctx);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error Context::addSignatureNotation(const char *name, const char *value, unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_sig_notation_add(d->ctx, name, value, add_to_gpgme_sig_notation_flags_t(0, flags)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error Context::addSignaturePolicyURL(const char *url, bool critical)
Packit Service 672cf4
{
Packit Service 0ef63b
    return Error(gpgme_sig_notation_add(d->ctx, nullptr, url, critical ? GPGME_SIG_NOTATION_CRITICAL : 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *Context::signaturePolicyURL() const
Packit Service 672cf4
{
Packit Service 672cf4
    for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) {
Packit Service 672cf4
        if (!n->name) {
Packit Service 672cf4
            return n->value;
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
    return nullptr;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Notation Context::signatureNotation(unsigned int idx) const
Packit Service 672cf4
{
Packit Service 672cf4
    for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) {
Packit Service 672cf4
        if (n->name) {
Packit Service 672cf4
            if (idx-- == 0) {
Packit Service 672cf4
                return Notation(n);
Packit Service 672cf4
            }
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
    return Notation();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::vector<Notation> Context::signatureNotations() const
Packit Service 672cf4
{
Packit Service 672cf4
    std::vector<Notation> result;
Packit Service 672cf4
    for (gpgme_sig_notation_t n = gpgme_sig_notation_get(d->ctx) ; n ; n = n->next) {
Packit Service 672cf4
        if (n->name) {
Packit Service 672cf4
            result.push_back(Notation(n));
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
    return result;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_sig_mode_t sigmode2sigmode(SignatureMode mode)
Packit Service 672cf4
{
Packit Service 672cf4
    switch (mode) {
Packit Service 672cf4
    default:
Packit Service 672cf4
    case NormalSignatureMode: return GPGME_SIG_MODE_NORMAL;
Packit Service 672cf4
    case Detached:            return GPGME_SIG_MODE_DETACH;
Packit Service 672cf4
    case Clearsigned:         return GPGME_SIG_MODE_CLEAR;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
SigningResult Context::sign(const Data &plainText, Data &signature, SignatureMode mode)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Sign;
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const sdp = signature.impl();
Packit Service 0ef63b
    d->lasterr = gpgme_op_sign(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigmode2sigmode(mode));
Packit Service 672cf4
    return SigningResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startSigning(const Data &plainText, Data &signature, SignatureMode mode)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Sign;
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const sdp = signature.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_sign_start(d->ctx, pdp ? pdp->data : nullptr, sdp ? sdp->data : nullptr, sigmode2sigmode(mode)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
SigningResult Context::signingResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::Sign) {
Packit Service 672cf4
        return SigningResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return SigningResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_encrypt_flags_t encryptflags2encryptflags(Context::EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    unsigned int result = 0;
Packit Service 672cf4
    if (flags & Context::AlwaysTrust) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_ALWAYS_TRUST;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::NoEncryptTo) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_NO_ENCRYPT_TO;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::Prepare) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_PREPARE;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::ExpectSign) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_EXPECT_SIGN;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::NoCompress) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_NO_COMPRESS;
Packit Service 672cf4
    }
Packit Service 672cf4
    if (flags & Context::Symmetric) {
Packit Service 672cf4
        result |= GPGME_ENCRYPT_SYMMETRIC;
Packit Service 672cf4
    }
Packit Service 672cf4
    return static_cast<gpgme_encrypt_flags_t>(result);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
gpgme_key_t *Context::getKeysFromRecipients(const std::vector<Key> &recipients)
Packit Service 672cf4
{
Packit Service 672cf4
    if (recipients.empty()) {
Packit Service 672cf4
        return nullptr;
Packit Service 672cf4
    }
Packit Service 672cf4
    gpgme_key_t *ret = new gpgme_key_t[ recipients.size() + 1 ];
Packit Service 672cf4
    gpgme_key_t *keys_it = ret;
Packit Service 672cf4
    for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
Packit Service 672cf4
        if (it->impl()) {
Packit Service 672cf4
            *keys_it++ = it->impl();
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 0ef63b
    *keys_it++ = nullptr;
Packit Service 672cf4
    return ret;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
EncryptionResult Context::encrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Encrypt;
Packit Service 672cf4
    if (flags & NoEncryptTo) {
Packit Service 672cf4
        return EncryptionResult(Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED)));
Packit Service 672cf4
    }
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
Packit Service 672cf4
    d->lasterr = gpgme_op_encrypt(d->ctx, keys, encryptflags2encryptflags(flags),
Packit Service 0ef63b
                                  pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr);
Packit Service 672cf4
    if (keys) {
Packit Service 672cf4
        delete[] keys;
Packit Service 672cf4
    }
Packit Service 672cf4
    return EncryptionResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::encryptSymmetrically(const Data &plainText, Data &cipherText)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Encrypt;
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const cdp = cipherText.impl();
Packit Service 0ef63b
    return Error(d->lasterr = gpgme_op_encrypt(d->ctx, nullptr, (gpgme_encrypt_flags_t)0,
Packit Service 0ef63b
                              pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::Encrypt;
Packit Service 672cf4
    if (flags & NoEncryptTo) {
Packit Service 672cf4
        return Error(d->lasterr = make_error(GPG_ERR_NOT_IMPLEMENTED));
Packit Service 672cf4
    }
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
Packit Service 672cf4
    d->lasterr = gpgme_op_encrypt_start(d->ctx, keys, encryptflags2encryptflags(flags),
Packit Service 0ef63b
                                        pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr);
Packit Service 672cf4
    if (keys) {
Packit Service 672cf4
        delete[] keys;
Packit Service 672cf4
    }
Packit Service 672cf4
    return Error(d->lasterr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
EncryptionResult Context::encryptionResult() const
Packit Service 672cf4
{
Packit Service 672cf4
    if (d->lastop & Private::Encrypt) {
Packit Service 672cf4
        return EncryptionResult(d->ctx, Error(d->lasterr));
Packit Service 672cf4
    } else {
Packit Service 672cf4
        return EncryptionResult();
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::pair<SigningResult, EncryptionResult> Context::signAndEncrypt(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::SignAndEncrypt;
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
Packit Service 672cf4
    d->lasterr = gpgme_op_encrypt_sign(d->ctx, keys, encryptflags2encryptflags(flags),
Packit Service 0ef63b
                                       pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr);
Packit Service 672cf4
    if (keys) {
Packit Service 672cf4
        delete[] keys;
Packit Service 672cf4
    }
Packit Service 672cf4
    return std::make_pair(SigningResult(d->ctx, Error(d->lasterr)),
Packit Service 672cf4
                          EncryptionResult(d->ctx, Error(d->lasterr)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCombinedSigningAndEncryption(const std::vector<Key> &recipients, const Data &plainText, Data &cipherText, EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::SignAndEncrypt;
Packit Service 672cf4
    const Data::Private *const pdp = plainText.impl();
Packit Service 672cf4
    Data::Private *const cdp = cipherText.impl();
Packit Service 672cf4
    gpgme_key_t *const keys = getKeysFromRecipients(recipients);
Packit Service 672cf4
    d->lasterr = gpgme_op_encrypt_sign_start(d->ctx, keys, encryptflags2encryptflags(flags),
Packit Service 0ef63b
                 pdp ? pdp->data : nullptr, cdp ? cdp->data : nullptr);
Packit Service 672cf4
    if (keys) {
Packit Service 672cf4
        delete[] keys;
Packit Service 672cf4
    }
Packit Service 672cf4
    return Error(d->lasterr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::createVFS(const char *containerFile, const std::vector< Key > &recipients)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::CreateVFS;
Packit Service 672cf4
    gpgme_key_t *const keys = new gpgme_key_t[ recipients.size() + 1 ];
Packit Service 672cf4
    gpgme_key_t *keys_it = keys;
Packit Service 672cf4
    for (std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it) {
Packit Service 672cf4
        if (it->impl()) {
Packit Service 672cf4
            *keys_it++ = it->impl();
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 0ef63b
    *keys_it++ = nullptr;
Packit Service 672cf4
Packit Service 672cf4
    gpgme_error_t op_err;
Packit Service 672cf4
    d->lasterr = gpgme_op_vfs_create(d->ctx, keys, containerFile, 0, &op_err);
Packit Service 672cf4
    delete[] keys;
Packit Service 672cf4
    Error error(d->lasterr);
Packit Service 672cf4
    if (error) {
Packit Service 672cf4
        return error;
Packit Service 672cf4
    }
Packit Service 672cf4
    return Error(d->lasterr = op_err);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
VfsMountResult Context::mountVFS(const char *containerFile, const char *mountDir)
Packit Service 672cf4
{
Packit Service 672cf4
    d->lastop = Private::MountVFS;
Packit Service 672cf4
    gpgme_error_t op_err;
Packit Service 672cf4
    d->lasterr = gpgme_op_vfs_mount(d->ctx, containerFile, mountDir, 0, &op_err);
Packit Service 672cf4
    return VfsMountResult(d->ctx, Error(d->lasterr), Error(op_err));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::cancelPendingOperation()
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(gpgme_cancel_async(d->ctx));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
bool Context::poll()
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_error_t e = GPG_ERR_NO_ERROR;
Packit Service 672cf4
    const bool finished = gpgme_wait(d->ctx, &e, 0);
Packit Service 672cf4
    if (finished) {
Packit Service 672cf4
        d->lasterr = e;
Packit Service 672cf4
    }
Packit Service 672cf4
    return finished;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::wait()
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_error_t e = GPG_ERR_NO_ERROR;
Packit Service 672cf4
    gpgme_wait(d->ctx, &e, 1);
Packit Service 672cf4
    return Error(d->lasterr = e);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::lastError() const
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Context::PinentryMode Context::pinentryMode() const
Packit Service 672cf4
{
Packit Service 672cf4
    switch (gpgme_get_pinentry_mode (d->ctx)) {
Packit Service 672cf4
        case GPGME_PINENTRY_MODE_ASK:
Packit Service 672cf4
            return PinentryAsk;
Packit Service 672cf4
        case GPGME_PINENTRY_MODE_CANCEL:
Packit Service 672cf4
            return PinentryCancel;
Packit Service 672cf4
        case GPGME_PINENTRY_MODE_ERROR:
Packit Service 672cf4
            return PinentryError;
Packit Service 672cf4
        case GPGME_PINENTRY_MODE_LOOPBACK:
Packit Service 672cf4
            return PinentryLoopback;
Packit Service 672cf4
        case GPGME_PINENTRY_MODE_DEFAULT:
Packit Service 672cf4
        default:
Packit Service 672cf4
            return PinentryDefault;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setPinentryMode(PinentryMode which)
Packit Service 672cf4
{
Packit Service 672cf4
    gpgme_pinentry_mode_t mode;
Packit Service 672cf4
    switch (which) {
Packit Service 672cf4
        case PinentryAsk:
Packit Service 672cf4
            mode = GPGME_PINENTRY_MODE_ASK;
Packit Service 672cf4
            break;
Packit Service 672cf4
        case PinentryCancel:
Packit Service 672cf4
            mode = GPGME_PINENTRY_MODE_CANCEL;
Packit Service 672cf4
            break;
Packit Service 672cf4
        case PinentryError:
Packit Service 672cf4
            mode = GPGME_PINENTRY_MODE_ERROR;
Packit Service 672cf4
            break;
Packit Service 672cf4
        case PinentryLoopback:
Packit Service 672cf4
            mode = GPGME_PINENTRY_MODE_LOOPBACK;
Packit Service 672cf4
            break;
Packit Service 672cf4
        case PinentryDefault:
Packit Service 672cf4
        default:
Packit Service 672cf4
            mode = GPGME_PINENTRY_MODE_DEFAULT;
Packit Service 672cf4
    }
Packit Service 672cf4
    return Error(d->lasterr = gpgme_set_pinentry_mode(d->ctx, mode));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static gpgme_tofu_policy_t to_tofu_policy_t(unsigned int policy)
Packit Service 672cf4
{
Packit Service 672cf4
    switch (policy) {
Packit Service 672cf4
        case TofuInfo::PolicyNone:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_NONE;
Packit Service 672cf4
        case TofuInfo::PolicyAuto:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_AUTO;
Packit Service 672cf4
        case TofuInfo::PolicyGood:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_GOOD;
Packit Service 672cf4
        case TofuInfo::PolicyBad:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_BAD;
Packit Service 672cf4
        case TofuInfo::PolicyAsk:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_ASK;
Packit Service 672cf4
        case TofuInfo::PolicyUnknown:
Packit Service 672cf4
        default:
Packit Service 672cf4
            return GPGME_TOFU_POLICY_UNKNOWN;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setTofuPolicy(const Key &k, unsigned int policy)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_tofu_policy(d->ctx,
Packit Service 672cf4
                 k.impl(), to_tofu_policy_t(policy)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::setTofuPolicyStart(const Key &k, unsigned int policy)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_tofu_policy_start(d->ctx,
Packit Service 672cf4
                 k.impl(), to_tofu_policy_t(policy)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCreateKey (const char *userid,
Packit Service 672cf4
                               const char *algo,
Packit Service 672cf4
                               unsigned long reserved,
Packit Service 672cf4
                               unsigned long expires,
Packit Service 672cf4
                               const Key &certkey,
Packit Service 672cf4
                               unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_createkey_start(d->ctx,
Packit Service 672cf4
                 userid,
Packit Service 672cf4
                 algo,
Packit Service 672cf4
                 reserved,
Packit Service 672cf4
                 expires,
Packit Service 672cf4
                 certkey.impl(),
Packit Service 672cf4
                 flags));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::createKey (const char *userid,
Packit Service 672cf4
                          const char *algo,
Packit Service 672cf4
                          unsigned long reserved,
Packit Service 672cf4
                          unsigned long expires,
Packit Service 672cf4
                          const Key &certkey,
Packit Service 672cf4
                          unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_createkey(d->ctx,
Packit Service 672cf4
                 userid,
Packit Service 672cf4
                 algo,
Packit Service 672cf4
                 reserved,
Packit Service 672cf4
                 expires,
Packit Service 672cf4
                 certkey.impl(),
Packit Service 672cf4
                 flags));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 0ef63b
KeyGenerationResult Context::createKeyEx (const char *userid,
Packit Service 0ef63b
                                          const char *algo,
Packit Service 0ef63b
                                          unsigned long reserved,
Packit Service 0ef63b
                                          unsigned long expires,
Packit Service 0ef63b
                                          const Key &certkey,
Packit Service 0ef63b
                                          unsigned int flags)
Packit Service 0ef63b
{
Packit Service 0ef63b
    d->lasterr = gpgme_op_createkey(d->ctx,
Packit Service 0ef63b
                 userid,
Packit Service 0ef63b
                 algo,
Packit Service 0ef63b
                 reserved,
Packit Service 0ef63b
                 expires,
Packit Service 0ef63b
                 certkey.impl(),
Packit Service 0ef63b
                 flags);
Packit Service 0ef63b
    return KeyGenerationResult(d->ctx, Error(d->lasterr));
Packit Service 0ef63b
}
Packit Service 0ef63b
Packit Service 672cf4
Error Context::addUid(const Key &k, const char *userid)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_adduid(d->ctx,
Packit Service 672cf4
                 k.impl(), userid, 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startAddUid(const Key &k, const char *userid)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_adduid_start(d->ctx,
Packit Service 672cf4
                 k.impl(), userid, 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::revUid(const Key &k, const char *userid)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_revuid(d->ctx,
Packit Service 672cf4
                 k.impl(), userid, 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startRevUid(const Key &k, const char *userid)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_revuid_start(d->ctx,
Packit Service 672cf4
                 k.impl(), userid, 0));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::createSubkey(const Key &k, const char *algo,
Packit Service 672cf4
                            unsigned long reserved,
Packit Service 672cf4
                            unsigned long expires,
Packit Service 672cf4
                            unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_createsubkey(d->ctx,
Packit Service 672cf4
                 k.impl(), algo, reserved, expires, flags));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::startCreateSubkey(const Key &k, const char *algo,
Packit Service 672cf4
                                 unsigned long reserved,
Packit Service 672cf4
                                 unsigned long expires,
Packit Service 672cf4
                                 unsigned int flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_createsubkey_start(d->ctx,
Packit Service 672cf4
                 k.impl(), algo, reserved, expires, flags));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 0ef63b
Error Context::setFlag(const char *name, const char *value)
Packit Service 0ef63b
{
Packit Service 0ef63b
  return Error(d->lasterr = gpgme_set_ctx_flag(d->ctx, name, value));
Packit Service 0ef63b
}
Packit Service 0ef63b
Packit Service 0ef63b
const char *Context::getFlag(const char *name) const
Packit Service 0ef63b
{
Packit Service 0ef63b
  return gpgme_get_ctx_flag(d->ctx, name);
Packit Service 0ef63b
}
Packit Service 0ef63b
Packit Service 672cf4
// Engine Spawn stuff
Packit Service 672cf4
Error Context::spawn(const char *file, const char *argv[],
Packit Service 672cf4
                     Data &input, Data &output, Data &err,
Packit Service 672cf4
                     SpawnFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_spawn (d->ctx, file, argv,
Packit Service 672cf4
        input.impl() ? input.impl()->data : nullptr,
Packit Service 672cf4
        output.impl() ? output.impl()->data : nullptr,
Packit Service 672cf4
        err.impl() ? err.impl()->data : nullptr,
Packit Service 672cf4
        static_cast<int>(flags)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error Context::spawnAsync(const char *file, const char *argv[],
Packit Service 672cf4
                          Data &input, Data &output, Data &err,
Packit Service 672cf4
                          SpawnFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    return Error(d->lasterr = gpgme_op_spawn_start (d->ctx, file, argv,
Packit Service 672cf4
        input.impl() ? input.impl()->data : nullptr,
Packit Service 672cf4
        output.impl() ? output.impl()->data : nullptr,
Packit Service 672cf4
        err.impl() ? err.impl()->data : nullptr,
Packit Service 672cf4
        static_cast<int>(flags)));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, Protocol proto)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::Protocol(";
Packit Service 672cf4
    switch (proto) {
Packit Service 672cf4
    case OpenPGP:
Packit Service 672cf4
        os << "OpenPGP";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case CMS:
Packit Service 672cf4
        os << "CMS";
Packit Service 672cf4
        break;
Packit Service 672cf4
    default:
Packit Service 672cf4
    case UnknownProtocol:
Packit Service 672cf4
        os << "UnknownProtocol";
Packit Service 672cf4
        break;
Packit Service 672cf4
    }
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, Engine eng)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::Engine(";
Packit Service 672cf4
    switch (eng) {
Packit Service 672cf4
    case GpgEngine:
Packit Service 672cf4
        os << "GpgEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case GpgSMEngine:
Packit Service 672cf4
        os << "GpgSMEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case GpgConfEngine:
Packit Service 672cf4
        os << "GpgConfEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case AssuanEngine:
Packit Service 672cf4
        os << "AssuanEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case SpawnEngine:
Packit Service 672cf4
        os << "SpawnEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    default:
Packit Service 672cf4
    case UnknownEngine:
Packit Service 672cf4
        os << "UnknownEngine";
Packit Service 672cf4
        break;
Packit Service 672cf4
    }
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, Context::CertificateInclusion incl)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::Context::CertificateInclusion(" << static_cast<int>(incl);
Packit Service 672cf4
    switch (incl) {
Packit Service 672cf4
    case Context::DefaultCertificates:
Packit Service 672cf4
        os << "(DefaultCertificates)";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case Context::AllCertificatesExceptRoot:
Packit Service 672cf4
        os << "(AllCertificatesExceptRoot)";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case Context::AllCertificates:
Packit Service 672cf4
        os << "(AllCertificates)";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case Context::NoCertificates:
Packit Service 672cf4
        os << "(NoCertificates)";
Packit Service 672cf4
        break;
Packit Service 672cf4
    case Context::OnlySenderCertificate:
Packit Service 672cf4
        os << "(OnlySenderCertificate)";
Packit Service 672cf4
        break;
Packit Service 672cf4
    }
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, KeyListMode mode)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::KeyListMode(";
Packit Service 672cf4
#define CHECK( x ) if ( !(mode & (x)) ) {} else do { os << #x " "; } while (0)
Packit Service 672cf4
    CHECK(Local);
Packit Service 672cf4
    CHECK(Extern);
Packit Service 672cf4
    CHECK(Signatures);
Packit Service 672cf4
    CHECK(Validate);
Packit Service 672cf4
    CHECK(Ephemeral);
Packit Service 672cf4
    CHECK(WithTofu);
Packit Service 672cf4
#undef CHECK
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, SignatureMode mode)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::SignatureMode(";
Packit Service 672cf4
    switch (mode) {
Packit Service 672cf4
#define CHECK( x ) case x: os << #x; break
Packit Service 672cf4
        CHECK(NormalSignatureMode);
Packit Service 672cf4
        CHECK(Detached);
Packit Service 672cf4
        CHECK(Clearsigned);
Packit Service 672cf4
#undef CHECK
Packit Service 672cf4
    default:
Packit Service 672cf4
        os << "???" "(" << static_cast<int>(mode) << ')';
Packit Service 672cf4
        break;
Packit Service 672cf4
    }
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, Context::EncryptionFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::Context::EncryptionFlags(";
Packit Service 672cf4
#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0)
Packit Service 672cf4
    CHECK(AlwaysTrust);
Packit Service 672cf4
    CHECK(NoEncryptTo);
Packit Service 672cf4
    CHECK(Prepare);
Packit Service 672cf4
    CHECK(ExpectSign);
Packit Service 672cf4
    CHECK(NoCompress);
Packit Service 672cf4
    CHECK(Symmetric);
Packit Service 672cf4
#undef CHECK
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
std::ostream &operator<<(std::ostream &os, Context::AuditLogFlags flags)
Packit Service 672cf4
{
Packit Service 672cf4
    os << "GpgME::Context::AuditLogFlags(";
Packit Service 672cf4
#define CHECK( x ) if ( !(flags & (Context::x)) ) {} else do { os << #x " "; } while (0)
Packit Service 672cf4
    CHECK(HtmlAuditLog);
Packit Service 672cf4
    CHECK(AuditLogWithHelp);
Packit Service 672cf4
#undef CHECK
Packit Service 672cf4
    return os << ')';
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
} // namespace GpgME
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error GpgME::setDefaultLocale(int cat, const char *val)
Packit Service 672cf4
{
Packit Service 0ef63b
    return Error(gpgme_set_locale(nullptr, cat, val));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::EngineInfo GpgME::engineInfo(GpgME::Protocol proto)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_engine_info_t ei = nullptr;
Packit Service 672cf4
    if (gpgme_get_engine_info(&ei)) {
Packit Service 672cf4
        return EngineInfo();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    const gpgme_protocol_t p = proto == CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP ;
Packit Service 672cf4
Packit Service 672cf4
    for (gpgme_engine_info_t i = ei ; i ; i = i->next) {
Packit Service 672cf4
        if (i->protocol == p) {
Packit Service 672cf4
            return EngineInfo(i);
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    return EngineInfo();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *GpgME::dirInfo(const char *what)
Packit Service 672cf4
{
Packit Service 672cf4
    return gpgme_get_dirinfo(what);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error GpgME::checkEngine(GpgME::Protocol proto)
Packit Service 672cf4
{
Packit Service 672cf4
    const gpgme_protocol_t p = proto == CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP ;
Packit Service 672cf4
Packit Service 672cf4
    return Error(gpgme_engine_check_version(p));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static const gpgme_protocol_t UNKNOWN_PROTOCOL = static_cast<gpgme_protocol_t>(255);
Packit Service 672cf4
Packit Service 672cf4
static gpgme_protocol_t engine2protocol(const GpgME::Engine engine)
Packit Service 672cf4
{
Packit Service 672cf4
    switch (engine) {
Packit Service 672cf4
    case GpgME::GpgEngine:   return GPGME_PROTOCOL_OpenPGP;
Packit Service 672cf4
    case GpgME::GpgSMEngine: return GPGME_PROTOCOL_CMS;
Packit Service 672cf4
    case GpgME::GpgConfEngine:
Packit Service 672cf4
        return GPGME_PROTOCOL_GPGCONF;
Packit Service 672cf4
    case GpgME::AssuanEngine:
Packit Service 672cf4
        return GPGME_PROTOCOL_ASSUAN;
Packit Service 672cf4
    case GpgME::G13Engine:
Packit Service 672cf4
        return GPGME_PROTOCOL_G13;
Packit Service 672cf4
    case GpgME::SpawnEngine:
Packit Service 672cf4
        return GPGME_PROTOCOL_SPAWN;
Packit Service 672cf4
    case GpgME::UnknownEngine:
Packit Service 672cf4
        ;
Packit Service 672cf4
    }
Packit Service 672cf4
    return UNKNOWN_PROTOCOL;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::EngineInfo GpgME::engineInfo(GpgME::Engine engine)
Packit Service 672cf4
{
Packit Service 0ef63b
    gpgme_engine_info_t ei = nullptr;
Packit Service 672cf4
    if (gpgme_get_engine_info(&ei)) {
Packit Service 672cf4
        return EngineInfo();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    const gpgme_protocol_t p = engine2protocol(engine);
Packit Service 672cf4
Packit Service 672cf4
    for (gpgme_engine_info_t i = ei ; i ; i = i->next) {
Packit Service 672cf4
        if (i->protocol == p) {
Packit Service 672cf4
            return EngineInfo(i);
Packit Service 672cf4
        }
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    return EngineInfo();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::Error GpgME::checkEngine(GpgME::Engine engine)
Packit Service 672cf4
{
Packit Service 672cf4
    const gpgme_protocol_t p = engine2protocol(engine);
Packit Service 672cf4
Packit Service 672cf4
    return Error(gpgme_engine_check_version(p));
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static const unsigned long supported_features = 0
Packit Service 672cf4
        | GpgME::ValidatingKeylistModeFeature
Packit Service 672cf4
        | GpgME::CancelOperationFeature
Packit Service 672cf4
        | GpgME::WrongKeyUsageFeature
Packit Service 672cf4
        | GpgME::DefaultCertificateInclusionFeature
Packit Service 672cf4
        | GpgME::GetSetEngineInfoFeature
Packit Service 672cf4
        | GpgME::ClearAddGetSignatureNotationsFeature
Packit Service 672cf4
        | GpgME::SetDataFileNameFeeature
Packit Service 672cf4
        | GpgME::SignatureNotationsKeylistModeFeature
Packit Service 672cf4
        | GpgME::KeySignatureNotationsFeature
Packit Service 672cf4
        | GpgME::KeyIsQualifiedFeature
Packit Service 672cf4
        | GpgME::SignatureNotationsCriticalFlagFeature
Packit Service 672cf4
        | GpgME::SignatureNotationsFlagsFeature
Packit Service 672cf4
        | GpgME::SignatureNotationsHumanReadableFlagFeature
Packit Service 672cf4
        | GpgME::SubkeyIsQualifiedFeature
Packit Service 672cf4
        | GpgME::EngineInfoHomeDirFeature
Packit Service 672cf4
        | GpgME::DecryptionResultFileNameFeature
Packit Service 672cf4
        | GpgME::DecryptionResultRecipientsFeature
Packit Service 672cf4
        | GpgME::VerificationResultFileNameFeature
Packit Service 672cf4
        | GpgME::SignaturePkaFieldsFeature
Packit Service 672cf4
        | GpgME::SignatureAlgorithmFieldsFeature
Packit Service 672cf4
        | GpgME::FdPointerFeature
Packit Service 672cf4
        | GpgME::AuditLogFeature
Packit Service 672cf4
        | GpgME::GpgConfEngineFeature
Packit Service 672cf4
        | GpgME::CancelOperationAsyncFeature
Packit Service 672cf4
        | GpgME::NoEncryptToEncryptionFlagFeature
Packit Service 672cf4
        | GpgME::CardKeyFeature
Packit Service 672cf4
        | GpgME::AssuanEngineFeature
Packit Service 672cf4
        | GpgME::EphemeralKeylistModeFeature
Packit Service 672cf4
        | GpgME::ImportFromKeyserverFeature
Packit Service 672cf4
        | GpgME::G13VFSFeature
Packit Service 672cf4
        | GpgME::PasswdFeature
Packit Service 672cf4
        ;
Packit Service 672cf4
Packit Service 672cf4
static const unsigned long supported_features2 = 0
Packit Service 672cf4
        | GpgME::BinaryAndFineGrainedIdentify
Packit Service 672cf4
        ;
Packit Service 672cf4
Packit Service 672cf4
bool GpgME::hasFeature(unsigned long features)
Packit Service 672cf4
{
Packit Service 672cf4
    return features == (features & supported_features);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
bool GpgME::hasFeature(unsigned long features, unsigned long features2)
Packit Service 672cf4
{
Packit Service 672cf4
    return features  == (features  & supported_features)
Packit Service 672cf4
           && features2 == (features2 & supported_features2)
Packit Service 672cf4
           ;
Packit Service 672cf4
}
Packit Service 0ef63b
Packit Service 0ef63b
int GpgME::setGlobalFlag(const char *name, const char *value)
Packit Service 0ef63b
{
Packit Service 0ef63b
    return gpgme_set_global_flag(name, value);
Packit Service 0ef63b
}