diff options
author | Ingo Klöcker <[email protected]> | 2020-09-08 12:55:20 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2020-09-08 12:55:20 +0000 |
commit | 3dd7377e120f10576b3b4334b6149f027ceec126 (patch) | |
tree | bf119f5de823c7f674f283cfaedbdd1d9b341bd8 /lang/cpp/src/key.cpp | |
parent | qt: List keys once with --with-secret instead of twice (diff) | |
download | gpgme-3dd7377e120f10576b3b4334b6149f027ceec126.tar.gz gpgme-3dd7377e120f10576b3b4334b6149f027ceec126.zip |
cpp: Update key with --with-secret instead of updating it twice
* lang/cpp/src/key.cpp (Key::update): Call Context::key() only once
with KeyListMode::WithSecret.
--
With gpg >= 2.1, get the key with --with-secret instead of first trying
to get the secret key and, if that fails, getting the public key.
GnuPG-bug-id: 4794
Diffstat (limited to 'lang/cpp/src/key.cpp')
-rw-r--r-- | lang/cpp/src/key.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index cb0c186e..4ebd3fe0 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -29,6 +29,7 @@ #include "util.h" #include "tofuinfo.h" #include "context.h" +#include "engineinfo.h" #include <gpgme.h> @@ -363,11 +364,17 @@ void Key::update() KeyListMode::SignatureNotations | KeyListMode::Validate | KeyListMode::WithTofu | - KeyListMode::WithKeygrip); + KeyListMode::WithKeygrip | + KeyListMode::WithSecret); Error err; - auto newKey = ctx->key(primaryFingerprint(), err, true); - // Not secret so we get the information from the pubring. - if (newKey.isNull()) { + Key newKey; + if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.0") { + newKey = ctx->key(primaryFingerprint(), err, true); + // Not secret so we get the information from the pubring. + if (newKey.isNull()) { + newKey = ctx->key(primaryFingerprint(), err, false); + } + } else { newKey = ctx->key(primaryFingerprint(), err, false); } delete ctx; @@ -375,7 +382,6 @@ void Key::update() return; } swap(newKey); - return; } // static |