gpgme/lang/cpp/src/decryptionresult.cpp

252 lines
6.4 KiB
C++
Raw Normal View History

Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New.
2016-02-22 17:28:08 +00:00
/*
decryptionresult.cpp - wraps a gpgme keygen result
Copyright (C) 2004 Klarälvdalens Datakonsult AB
qt, cpp: Add additional copyright BSI notes * lang/cpp/Makefile.am, lang/cpp/src/Makefile.am, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/qt/Makefile.am, lang/qt/doc/Makefile.am, lang/qt/src/Makefile.am, lang/qt/src/defaultkeygenerationjob.h, lang/qt/tests/Makefile.am: Add missing copyright. -- Moving the qt / cpp bindings into GPGME contained global changes that modified nearly every source file. To reflect that the copyright year / note should also be updated.
2017-04-25 11:03:49 +00:00
2016 Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New.
2016-02-22 17:28:08 +00:00
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
cpp, qt: Include config.h lang/cpp/src/callbacks.cpp, lang/cpp/src/configuration.cpp, lang/cpp/src/context.cpp, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/editinteractor.cpp, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/engineinfo.cpp, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/exception.cpp, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/importresult.cpp, lang/cpp/src/key.cpp, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keylistresult.cpp, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/signingresult.cpp, lang/cpp/src/tofuinfo.cpp, lang/cpp/src/trustitem.cpp, lang/cpp/src/verificationresult.cpp, lang/cpp/src/vfsmountresult.cpp, lang/qt/src/dataprovider.cpp, lang/qt/src/defaultkeygenerationjob.cpp, lang/qt/src/gpgme_backend_debug.cpp, lang/qt/src/job.cpp, lang/qt/src/qgpgmeadduseridjob.cpp, lang/qt/src/qgpgmebackend.cpp, lang/qt/src/qgpgmechangeexpiryjob.cpp, lang/qt/src/qgpgmechangeownertrustjob.cpp, lang/qt/src/qgpgmechangepasswdjob.cpp, lang/qt/src/qgpgmedecryptjob.cpp, lang/qt/src/qgpgmedecryptverifyjob.cpp, lang/qt/src/qgpgmedeletejob.cpp, lang/qt/src/qgpgmedownloadjob.cpp, lang/qt/src/qgpgmeencryptjob.cpp, lang/qt/src/qgpgmeexportjob.cpp, lang/qt/src/qgpgmeimportfromkeyserverjob.cpp, lang/qt/src/qgpgmeimportjob.cpp, lang/qt/src/qgpgmekeyformailboxjob.cpp, lang/qt/src/qgpgmekeygenerationjob.cpp, lang/qt/src/qgpgmekeylistjob.cpp, lang/qt/src/qgpgmelistallkeysjob.cpp, lang/qt/src/qgpgmenewcryptoconfig.cpp, lang/qt/src/qgpgmerefreshkeysjob.cpp, lang/qt/src/qgpgmesecretkeyexportjob.cpp, lang/qt/src/qgpgmesignencryptjob.cpp, lang/qt/src/qgpgmesignjob.cpp, lang/qt/src/qgpgmesignkeyjob.cpp, lang/qt/src/qgpgmetofupolicyjob.cpp, lang/qt/src/qgpgmeverifydetachedjob.cpp, lang/qt/src/qgpgmeverifyopaquejob.cpp, lang/qt/src/qgpgmewkspublishjob.cpp, lang/qt/src/threadedjobmixin.cpp, lang/qt/tests/run-keyformailboxjob.cpp, lang/qt/tests/t-encrypt.cpp, lang/qt/tests/t-keylist.cpp, lang/qt/tests/t-keylocate.cpp, lang/qt/tests/t-ownertrust.cpp, lang/qt/tests/t-support.cpp, lang/qt/tests/t-tofuinfo.cpp, lang/qt/tests/t-wkspublish.cpp: Include config.h -- This fixes problems with mismatching definitions. Most notably _FILE_OFFSET_BITS is now always set correctly.
2016-09-23 13:22:29 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New.
2016-02-22 17:28:08 +00:00
#include <decryptionresult.h>
#include "result_p.h"
#include "util.h"
#include <gpgme.h>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <cstdlib>
#include <istream>
#include <string.h>
class GpgME::DecryptionResult::Private
{
public:
explicit Private(const _gpgme_op_decrypt_result &r) : res(r)
{
if (res.unsupported_algorithm) {
res.unsupported_algorithm = strdup(res.unsupported_algorithm);
}
if (res.file_name) {
res.file_name = strdup(res.file_name);
}
//FIXME: copying gpgme_recipient_t objects invalidates the keyid member,
//thus we use _keyid for now (internal API)
for (gpgme_recipient_t r = res.recipients ; r ; r = r->next) {
recipients.push_back(*r);
}
res.recipients = 0;
}
~Private()
{
if (res.unsupported_algorithm) {
std::free(res.unsupported_algorithm);
}
res.unsupported_algorithm = 0;
if (res.file_name) {
std::free(res.file_name);
}
res.file_name = 0;
}
_gpgme_op_decrypt_result res;
std::vector<_gpgme_recipient> recipients;
};
GpgME::DecryptionResult::DecryptionResult(gpgme_ctx_t ctx, int error)
: GpgME::Result(error), d()
{
init(ctx);
}
GpgME::DecryptionResult::DecryptionResult(gpgme_ctx_t ctx, const Error &error)
: GpgME::Result(error), d()
{
init(ctx);
}
void GpgME::DecryptionResult::init(gpgme_ctx_t ctx)
{
if (!ctx) {
return;
}
gpgme_decrypt_result_t res = gpgme_op_decrypt_result(ctx);
if (!res) {
return;
}
d.reset(new Private(*res));
}
make_standard_stuff(DecryptionResult)
const char *GpgME::DecryptionResult::unsupportedAlgorithm() const
{
return d ? d->res.unsupported_algorithm : 0 ;
}
bool GpgME::DecryptionResult::isWrongKeyUsage() const
{
return d && d->res.wrong_key_usage;
}
bool GpgME::DecryptionResult::isDeVs() const
{
return d && d->res.is_de_vs;
}
Initial checkin of gpgmepp sources Based on git.kde.org/pim/gpgmepp rev. 0e3ebc02 * lang/cpp/src/assuanresult.cpp, lang/cpp/src/assuanresult.h, lang/cpp/src/callbacks.cpp, lang/cpp/src/callbacks.h, lang/cpp/src/configuration.cpp, lang/cpp/src/configuration.h, lang/cpp/src/context.cpp, lang/cpp/src/context.h, lang/cpp/src/context_glib.cpp, lang/cpp/src/context_p.h, lang/cpp/src/context_qt.cpp, lang/cpp/src/context_vanilla.cpp, lang/cpp/src/data.cpp, lang/cpp/src/data.h, lang/cpp/src/data_p.h, lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h, lang/cpp/src/defaultassuantransaction.cpp, lang/cpp/src/defaultassuantransaction.h, lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h, lang/cpp/src/encryptionresult.cpp, lang/cpp/src/encryptionresult.h, lang/cpp/src/engineinfo.cpp, lang/cpp/src/engineinfo.h, lang/cpp/src/error.h, lang/cpp/src/eventloopinteractor.cpp, lang/cpp/src/eventloopinteractor.h, lang/cpp/src/exception.cpp, lang/cpp/src/exception.h, lang/cpp/src/global.h, lang/cpp/src/gpgadduserideditinteractor.cpp, lang/cpp/src/gpgadduserideditinteractor.h, lang/cpp/src/gpgagentgetinfoassuantransaction.cpp, lang/cpp/src/gpgagentgetinfoassuantransaction.h, lang/cpp/src/gpgmefw.h, lang/cpp/src/gpgmepp_export.h, lang/cpp/src/gpgsetexpirytimeeditinteractor.cpp, lang/cpp/src/gpgsetexpirytimeeditinteractor.h, lang/cpp/src/gpgsetownertrusteditinteractor.cpp, lang/cpp/src/gpgsetownertrusteditinteractor.h, lang/cpp/src/gpgsignkeyeditinteractor.cpp, lang/cpp/src/gpgsignkeyeditinteractor.h, lang/cpp/src/importresult.cpp, lang/cpp/src/importresult.h, lang/cpp/src/key.cpp, lang/cpp/src/key.h, lang/cpp/src/keygenerationresult.cpp, lang/cpp/src/keygenerationresult.h, lang/cpp/src/keylistresult.cpp, lang/cpp/src/keylistresult.h, lang/cpp/src/notation.h, lang/cpp/src/result.h, lang/cpp/src/result_p.h, lang/cpp/src/scdgetinfoassuantransaction.cpp, lang/cpp/src/scdgetinfoassuantransaction.h, lang/cpp/src/signingresult.cpp, lang/cpp/src/signingresult.h, lang/cpp/src/trustitem.cpp, lang/cpp/src/trustitem.h, lang/cpp/src/util.h, lang/cpp/src/verificationresult.cpp, lang/cpp/src/verificationresult.h, lang/cpp/src/vfsmountresult.cpp, lang/cpp/src/vfsmountresult.h, lang/cpp/src/interfaces/assuantransaction.h, lang/cpp/src/interfaces/dataprovider.h, lang/cpp/src/interfaces/passphraseprovider.h, lang/cpp/src/interfaces/progressprovider.h: New.
2016-02-22 17:28:08 +00:00
const char *GpgME::DecryptionResult::fileName() const
{
return d ? d->res.file_name : 0 ;
}
unsigned int GpgME::DecryptionResult::numRecipients() const
{
return d ? d->recipients.size() : 0 ;
}
GpgME::DecryptionResult::Recipient GpgME::DecryptionResult::recipient(unsigned int idx) const
{
if (d && idx < d->recipients.size()) {
return Recipient(&d->recipients[idx]);
}
return Recipient();
}
namespace
{
struct make_recipient {
GpgME::DecryptionResult::Recipient operator()(_gpgme_recipient &t)
{
return GpgME::DecryptionResult::Recipient(&t);
}
};
}
std::vector<GpgME::DecryptionResult::Recipient> GpgME::DecryptionResult::recipients() const
{
std::vector<Recipient> result;
if (d) {
result.reserve(d->recipients.size());
std::transform(d->recipients.begin(), d->recipients.end(),
std::back_inserter(result),
make_recipient());
}
return result;
}
class GpgME::DecryptionResult::Recipient::Private : public _gpgme_recipient
{
public:
Private(gpgme_recipient_t reci) : _gpgme_recipient(*reci) {}
};
GpgME::DecryptionResult::Recipient::Recipient()
: d()
{
}
GpgME::DecryptionResult::Recipient::Recipient(gpgme_recipient_t r)
: d()
{
if (r) {
d.reset(new Private(r));
}
}
bool GpgME::DecryptionResult::Recipient::isNull() const
{
return !d;
}
const char *GpgME::DecryptionResult::Recipient::keyID() const
{
//_keyid is internal API, but the public keyid is invalid after copying (see above)
if (d) {
return d->_keyid;
}
return 0;
}
const char *GpgME::DecryptionResult::Recipient::shortKeyID() const
{
//_keyid is internal API, but the public keyid is invalid after copying (see above)
if (d) {
return d->_keyid + 8;
}
return 0;
}
unsigned int GpgME::DecryptionResult::Recipient::publicKeyAlgorithm() const
{
if (d) {
return d->pubkey_algo;
}
return 0;
}
const char *GpgME::DecryptionResult::Recipient::publicKeyAlgorithmAsString() const
{
if (d) {
return gpgme_pubkey_algo_name(d->pubkey_algo);
}
return 0;
}
GpgME::Error GpgME::DecryptionResult::Recipient::status() const
{
if (d) {
return Error(d->status);
}
return Error();
}
std::ostream &GpgME::operator<<(std::ostream &os, const DecryptionResult &result)
{
os << "GpgME::DecryptionResult(";
if (!result.isNull()) {
os << "\n error: " << result.error()
<< "\n fileName: " << protect(result.fileName())
<< "\n unsupportedAlgorithm: " << protect(result.unsupportedAlgorithm())
<< "\n isWrongKeyUsage: " << result.isWrongKeyUsage()
<< "\n recipients:\n";
const std::vector<DecryptionResult::Recipient> recipients = result.recipients();
std::copy(recipients.begin(), recipients.end(),
std::ostream_iterator<DecryptionResult::Recipient>(os, "\n"));
}
return os << ')';
}
std::ostream &GpgME::operator<<(std::ostream &os, const DecryptionResult::Recipient &reci)
{
os << "GpgME::DecryptionResult::Recipient(";
if (!reci.isNull()) {
os << "\n keyID: " << protect(reci.keyID())
<< "\n shortKeyID: " << protect(reci.shortKeyID())
<< "\n publicKeyAlgorithm: " << protect(reci.publicKeyAlgorithmAsString())
<< "\n status: " << reci.status();
}
return os << ')';
}