[Pkg-gnupg-commit] [gpgme] 29/53: Add convenience function to get key from sig

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Oct 24 19:26:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit b6b820bff14a9aa8fa67755b246c90062ffdba14
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Mon Oct 10 17:38:43 2016 +0200

    Add convenience function to get key from sig
    
    * lang/cpp/src/verificationresult.cpp (Signature::key(bool, bool)):
    New. Can be used to search / update the key associcated with this
    signature.
    
    --
    By using update a caller can ensure that an incomplete key
    obtainable through the new key() function is fully loaded.
    With search the key can be looked up in the internal keyring.
    
    As the results are cached this can be done in the crypto thread
    and the result then better used in the UI thread.
---
 lang/cpp/src/verificationresult.cpp | 32 ++++++++++++++++++++++++++++++++
 lang/cpp/src/verificationresult.h   | 21 +++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/lang/cpp/src/verificationresult.cpp b/lang/cpp/src/verificationresult.cpp
index a7b073e..23c458e 100644
--- a/lang/cpp/src/verificationresult.cpp
+++ b/lang/cpp/src/verificationresult.cpp
@@ -29,6 +29,7 @@
 #include "result_p.h"
 #include "util.h"
 #include "key.h"
+#include "context.h"
 
 #include <gpgme.h>
 
@@ -121,6 +122,7 @@ public:
     std::vector<GpgME::Key> keys;
     std::vector<char *> purls;
     std::string file_name;
+    Protocol proto;
 };
 
 GpgME::VerificationResult::VerificationResult(gpgme_ctx_t ctx, int error)
@@ -145,6 +147,10 @@ void GpgME::VerificationResult::init(gpgme_ctx_t ctx)
         return;
     }
     d.reset(new Private(res));
+    gpgme_protocol_t proto = gpgme_get_protocol(ctx);
+    d->proto = proto == GPGME_PROTOCOL_OpenPGP ? OpenPGP :
+               proto == GPGME_PROTOCOL_CMS ? CMS :
+               UnknownProtocol;
 }
 
 make_standard_stuff(VerificationResult)
@@ -386,6 +392,32 @@ GpgME::Key GpgME::Signature::key() const
     return d->keys[idx];
 }
 
+GpgME::Key GpgME::Signature::key(bool search, bool update) const
+{
+    if (isNull()) {
+        return Key();
+    }
+
+    GpgME::Key ret = key();
+    if (ret.isNull() && search) {
+        auto ctx = Context::createForProtocol (d->proto);
+        if (ctx) {
+            ctx->setKeyListMode(KeyListMode::Local |
+                        KeyListMode::Signatures |
+                        KeyListMode::SignatureNotations |
+                        KeyListMode::Validate |
+                        KeyListMode::WithTofu);
+            Error e;
+            ret = d->keys[idx] = ctx->key(fingerprint(), e, false);
+            delete ctx;
+        }
+    }
+    if (update) {
+        ret.update();
+    }
+    return ret;
+}
+
 class GpgME::Notation::Private
 {
 public:
diff --git a/lang/cpp/src/verificationresult.h b/lang/cpp/src/verificationresult.h
index 93288af..b6d1d8c 100644
--- a/lang/cpp/src/verificationresult.h
+++ b/lang/cpp/src/verificationresult.h
@@ -163,6 +163,27 @@ public:
      * set or the associated TOFU Information if applicable. */
     GpgME::Key key() const;
 
+    /* Search / Update the key of this signature.
+     *
+     * Same as above but if search is set to true this will
+     * either update the key provided by the engine or search
+     * the key in the engine. The key is cached.
+     *
+     * As this involves an engine call it might take some time
+     * to finish so it should be avoided to do this in a UI
+     * thread. The result will be cached and no engine call
+     * will be done if update is set to false and a key is
+     * already cached.
+     *
+     * If no key was provided by the engine this will look
+     * up the key so this call might block while the engine
+     * is called to obtain the key.
+     *
+     * If both search and update are false this is the same
+     * as calling key()
+     */
+    GpgME::Key key(bool search, bool update) const;
+
 private:
     std::shared_ptr<VerificationResult::Private> d;
     unsigned int idx;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list