Commit 91932227 authored by Justus Winter's avatar Justus Winter

Add helper for dealing with compliance modes

Add a predicate to check whether we are in a given compliance mode, a
function that computes the minimum of the validity of all UIDs, and a
macro that can be used to check various objects for compliance with
CO_DE_VS without breaking compilation with older versions of GPGME,
and without cluttering the code with preprocessor conditionals.
Signed-off-by: default avatarJustus Winter <>
parent 10c53a98
......@@ -40,6 +40,7 @@
#include <gpgme++/engineinfo.h>
#include <gpgme++/error.h>
#include <gpgme++/key.h>
#include <QGpgME/Protocol>
#include <QGpgME/CryptoConfig>
......@@ -275,3 +276,26 @@ bool Kleo::haveKeyserverConfigured()
const QGpgME::CryptoConfigEntry *const entry = config->entry(QStringLiteral("gpg"), QStringLiteral("Keyserver"), QStringLiteral("keyserver"));
return entry && !entry->stringValue().isEmpty();
bool Kleo::gpgComplianceP(const char *mode)
auto conf = QGpgME::cryptoConfig();
return (conf->entry(QStringLiteral("gpg"),
== QString(mode));
enum GpgME::UserID::Validity Kleo::keyValidity(const GpgME::Key &key)
enum UserID::Validity validity = UserID::Validity::Unknown;
for (const auto &uid: key.userIDs()) {
if (validity == UserID::Validity::Unknown
|| validity > uid.validity()) {
validity = uid.validity();
return validity;
......@@ -34,6 +34,22 @@
#include <gpgme++/engineinfo.h>
#include <gpgme++/key.h>
/* Support compilation with GPGME older than 1.9. */
#include <gpgme++/gpgmepp_version.h>
#if GPGMEPP_VERSION >= 0x10900
/* Does the given object comply with DE_VS? This macro can be used to
ensure that we can still build against older versions of GPGME
without cluttering the code with preprocessor conditionals. */
# define IS_DE_VS(x) (x).isDeVs()
# define IS_DE_VS(x) false
class QString;
class QStringList;
......@@ -59,6 +75,8 @@ int makeGnuPGError(int code);
bool engineIsVersion(int major, int minor, int patch, GpgME::Engine = GpgME::GpgConfEngine);
bool haveKeyserverConfigured();
bool gpgComplianceP(const char *mode);
enum GpgME::UserID::Validity keyValidity(const GpgME::Key &key);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment