aboutsummaryrefslogtreecommitdiffstats
path: root/lang/cpp/src
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2018-02-16 11:58:54 +0000
committerAndre Heinecke <[email protected]>2018-02-16 12:00:49 +0000
commit7f9d5c6cd204bfd84ea477b284df795b1dadb1af (patch)
treef0db6da93e3442f4c76095feb610375cf2309873 /lang/cpp/src
parenttests: Fix previous commit (diff)
downloadgpgme-7f9d5c6cd204bfd84ea477b284df795b1dadb1af.tar.gz
gpgme-7f9d5c6cd204bfd84ea477b284df795b1dadb1af.zip
cpp: Add shorthand for key locate
* lang/cpp/src/key.cpp (Key::locate): New static helper. * lang/cpp/src/key.h: Update accordingly.
Diffstat (limited to 'lang/cpp/src')
-rw-r--r--lang/cpp/src/key.cpp21
-rw-r--r--lang/cpp/src/key.h14
2 files changed, 35 insertions, 0 deletions
diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp
index 66fdea96..0e86a19e 100644
--- a/lang/cpp/src/key.cpp
+++ b/lang/cpp/src/key.cpp
@@ -371,6 +371,27 @@ void Key::update()
return;
}
+// static
+Key Key::locate(const char *mbox)
+{
+ if (!mbox) {
+ return Key();
+ }
+
+ auto ctx = Context::createForProtocol(OpenPGP);
+ if (!ctx) {
+ return Key();
+ }
+
+ ctx->setKeyListMode (Extern | Local);
+
+ Error e = ctx->startKeyListing (mbox);
+ auto ret = ctx->nextKey (e);
+ delete ctx;
+
+ return ret;
+}
+
//
//
// class Subkey
diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h
index 829bd266..c3c711c1 100644
--- a/lang/cpp/src/key.h
+++ b/lang/cpp/src/key.h
@@ -164,6 +164,20 @@ public:
* @returns a possible error.
**/
Error addUid(const char *uid);
+
+ /**
+ * @brief try to locate the best pgp key for a given mailbox.
+ *
+ * Boils down to gpg --locate-key <mbox>
+ * This may take some time if remote sources are also
+ * used.
+ *
+ * @param mbox should be a mail address does not need to be normalized.
+ *
+ * @returns The best key for a mailbox or a null key.
+ */
+ static Key locate(const char *mbox);
+
private:
gpgme_key_t impl() const
{