Cpp: Move tofuinfo from signature to userid

* lang/cpp/src/key.cpp (UserID::tofuInfo): New.
* lang/cpp/src/key.h: Update accordingly.
* lang/cpp/src/tofuinfo.cpp: Remove dropped fields.
* lang/cpp/src/tofuinfo.h: Update accordingly.
* lang/cpp/src/verificationresult.cpp,
lang/cpp/src/verificationresult.h: Remove tofu info.
* lang/qt/tests/t-tofuinfo.cpp: Disable for now.

--
With be4ff75d7 Tofu info now lives with a UserID
Object. While this breaks API it was not yet released.
This commit is contained in:
Andre Heinecke 2016-08-23 16:40:21 +02:00
parent 2972c44bd7
commit 799b168243
7 changed files with 17 additions and 72 deletions

View File

@ -23,6 +23,7 @@
#include <key.h> #include <key.h>
#include "util.h" #include "util.h"
#include "tofuinfo.h"
#include <gpgme.h> #include <gpgme.h>
@ -625,6 +626,14 @@ bool UserID::isInvalid() const
return uid && uid->invalid; return uid && uid->invalid;
} }
TofuInfo UserID::tofuInfo() const
{
if (!uid) {
return TofuInfo();
}
return TofuInfo(uid->tofu);
}
// //
// //
// class Signature // class Signature

View File

@ -43,6 +43,7 @@ class Context;
class Subkey; class Subkey;
class UserID; class UserID;
class TofuInfo;
typedef std::shared_ptr< std::remove_pointer<gpgme_key_t>::type > shared_gpgme_key_t; typedef std::shared_ptr< std::remove_pointer<gpgme_key_t>::type > shared_gpgme_key_t;
@ -309,6 +310,10 @@ public:
bool isRevoked() const; bool isRevoked() const;
bool isInvalid() const; bool isInvalid() const;
/** TOFU info for this userid.
* @returns The TOFU stats or a null TofuInfo.
*/
GpgME::TofuInfo tofuInfo() const;
private: private:
shared_gpgme_key_t key; shared_gpgme_key_t key;
gpgme_user_id_t uid; gpgme_user_id_t uid;

View File

@ -31,12 +31,6 @@ public:
Private(gpgme_tofu_info_t info) Private(gpgme_tofu_info_t info)
: mInfo(info ? new _gpgme_tofu_info(*info) : nullptr) : mInfo(info ? new _gpgme_tofu_info(*info) : nullptr)
{ {
if (mInfo && mInfo->fpr) {
mInfo->fpr = strdup(mInfo->fpr);
}
if (mInfo && mInfo->address) {
mInfo->address = strdup(mInfo->address);
}
if (mInfo && mInfo->description) { if (mInfo && mInfo->description) {
mInfo->description = strdup(mInfo->description); mInfo->description = strdup(mInfo->description);
} }
@ -45,12 +39,6 @@ public:
Private(const Private &other) Private(const Private &other)
: mInfo(other.mInfo) : mInfo(other.mInfo)
{ {
if (mInfo && mInfo->fpr) {
mInfo->fpr = strdup(mInfo->fpr);
}
if (mInfo && mInfo->address) {
mInfo->address = strdup(mInfo->address);
}
if (mInfo && mInfo->description) { if (mInfo && mInfo->description) {
mInfo->description = strdup(mInfo->description); mInfo->description = strdup(mInfo->description);
} }
@ -59,10 +47,6 @@ public:
~Private() ~Private()
{ {
if (mInfo) { if (mInfo) {
std::free(mInfo->fpr);
mInfo->fpr = nullptr;
std::free(mInfo->address);
mInfo->address = nullptr;
std::free(mInfo->description); std::free(mInfo->description);
mInfo->description = nullptr; mInfo->description = nullptr;
@ -129,16 +113,6 @@ GpgME::TofuInfo::Policy GpgME::TofuInfo::policy() const
} }
} }
const char *GpgME::TofuInfo::fingerprint() const
{
return isNull() ? nullptr : d->mInfo->fpr;
}
const char *GpgME::TofuInfo::address() const
{
return isNull() ? nullptr : d->mInfo->address;
}
const char *GpgME::TofuInfo::description() const const char *GpgME::TofuInfo::description() const
{ {
return isNull() ? nullptr : d->mInfo->description; return isNull() ? nullptr : d->mInfo->description;
@ -163,9 +137,7 @@ std::ostream &GpgME::operator<<(std::ostream &os, const GpgME::TofuInfo &info)
{ {
os << "GpgME::Signature::TofuInfo("; os << "GpgME::Signature::TofuInfo(";
if (!info.isNull()) { if (!info.isNull()) {
os << "\n address: " << protect(info.address()) os << "\n desc: " << protect(info.description())
<< "\n fpr: " << protect(info.fingerprint())
<< "\n desc: " << protect(info.description())
<< "\n validity: " << info.validity() << "\n validity: " << info.validity()
<< "\n policy: " << info.policy() << "\n policy: " << info.policy()
<< "\n signcount: "<< info.signCount() << "\n signcount: "<< info.signCount()

View File

@ -99,20 +99,9 @@ public:
/* Number of seconds since the last message was verified. */ /* Number of seconds since the last message was verified. */
unsigned int lastSeen() const; unsigned int lastSeen() const;
/* Finterprint of the key for this entry. */
const char *fingerprint() const;
/* If non-NULL a human readable string summarizing the TOFU data. */ /* If non-NULL a human readable string summarizing the TOFU data. */
const char *description() const; const char *description() const;
/* The address of the tofu binding.
*
* If no mail address is set for a User ID this is the name used
* for the user ID. Can be ambiguous when the same mail address or
* name is used in multiple user ids.
*/
const char *address() const;
private: private:
class Private; class Private;
std::shared_ptr<Private> d; std::shared_ptr<Private> d;

View File

@ -24,7 +24,6 @@
#include <notation.h> #include <notation.h>
#include "result_p.h" #include "result_p.h"
#include "util.h" #include "util.h"
#include "tofuinfo.h"
#include <gpgme.h> #include <gpgme.h>
@ -82,11 +81,6 @@ public:
} }
nota.back().push_back(n); nota.back().push_back(n);
} }
// copy tofu info:
tinfos.push_back(std::vector<TofuInfo>());
for (gpgme_tofu_info_t in = is->tofu; in ; in = in->next) {
tinfos.back().push_back(TofuInfo(in));
}
} }
} }
~Private() ~Private()
@ -113,7 +107,6 @@ public:
std::vector<gpgme_signature_t> sigs; std::vector<gpgme_signature_t> sigs;
std::vector< std::vector<Nota> > nota; std::vector< std::vector<Nota> > nota;
std::vector< std::vector<TofuInfo> > tinfos;
std::vector<char *> purls; std::vector<char *> purls;
std::string file_name; std::string file_name;
}; };
@ -373,15 +366,6 @@ std::vector<GpgME::Notation> GpgME::Signature::notations() const
return result; return result;
} }
std::vector<GpgME::TofuInfo> GpgME::Signature::tofuInfo() const
{
if (isNull()) {
return std::vector<GpgME::TofuInfo>();
}
return d->tinfos[idx];
}
class GpgME::Notation::Private class GpgME::Notation::Private
{ {
public: public:
@ -550,9 +534,6 @@ std::ostream &GpgME::operator<<(std::ostream &os, const Signature &sig)
const std::vector<Notation> nota = sig.notations(); const std::vector<Notation> nota = sig.notations();
std::copy(nota.begin(), nota.end(), std::copy(nota.begin(), nota.end(),
std::ostream_iterator<Notation>(os, "\n")); std::ostream_iterator<Notation>(os, "\n"));
const std::vector<TofuInfo> tinfos = sig.tofuInfo();
std::copy(tinfos.begin(), tinfos.end(),
std::ostream_iterator<TofuInfo>(os, "\n"));
} }
return os << ')'; return os << ')';
} }

View File

@ -40,7 +40,6 @@ namespace GpgME
class Error; class Error;
class Signature; class Signature;
class Notation; class Notation;
class TofuInfo;
class GPGMEPP_EXPORT VerificationResult : public Result class GPGMEPP_EXPORT VerificationResult : public Result
{ {
@ -158,18 +157,6 @@ public:
GpgME::Notation notation(unsigned int index) const; GpgME::Notation notation(unsigned int index) const;
std::vector<GpgME::Notation> notations() const; std::vector<GpgME::Notation> notations() const;
/** List of TOFU stats for this signature.
*
* For each UserID of the key used to create this
* signature a tofu entry is returned.
*
* Warning: Addresses can be ambigous if there are multiple UserID's
* with the same mailbox in a key.
*
* @returns The list of TOFU stats.
*/
std::vector<GpgME::TofuInfo> tofuInfo() const;
private: private:
std::shared_ptr<VerificationResult::Private> d; std::shared_ptr<VerificationResult::Private> d;
unsigned int idx; unsigned int idx;

View File

@ -57,6 +57,7 @@ static const char testMsg1[] =
class TofuInfoTest: public QGpgMETest class TofuInfoTest: public QGpgMETest
{ {
#if 0
Q_OBJECT Q_OBJECT
void testTofuCopy(TofuInfo other, const TofuInfo &orig) void testTofuCopy(TofuInfo other, const TofuInfo &orig)
@ -235,6 +236,7 @@ private /* FIXME Disabled until GnuPG-Bug-Id 2405 is fixed Q_SLOTS */:
mDir.path() + QStringLiteral("/secring.gpg"))); mDir.path() + QStringLiteral("/secring.gpg")));
} }
#endif
}; };
QTEST_MAIN(TofuInfoTest) QTEST_MAIN(TofuInfoTest)