cpp: Add shorthand for key locate

* lang/cpp/src/key.cpp (Key::locate): New static helper.
* lang/cpp/src/key.h: Update accordingly.
This commit is contained in:
Andre Heinecke 2018-02-16 12:58:54 +01:00
parent 3224d7f0ea
commit 7f9d5c6cd2
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
3 changed files with 41 additions and 0 deletions

6
NEWS
View File

@ -1,6 +1,12 @@
Noteworthy changes in version 1.10.1 (unreleased)
-------------------------------------------------
* Interface changes relative to the 1.10.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cpp: Key::locate NEW.
cpp: Data::toString NEW.
Noteworthy changes in version 1.10.0 (2017-12-12)
-------------------------------------------------

View File

@ -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

View File

@ -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
{