diff options
author | Andre Heinecke <[email protected]> | 2017-03-22 15:38:35 +0000 |
---|---|---|
committer | Andre Heinecke <[email protected]> | 2017-03-22 15:43:33 +0000 |
commit | 8ddb42ada46f00d8393f6c2df7d6b79a4a5878f0 (patch) | |
tree | 0c440c121b54f53330e42da51dc561e85227b851 /lang/cpp/src/data.cpp | |
parent | qt: Initialize library first in tests (diff) | |
download | gpgme-8ddb42ada46f00d8393f6c2df7d6b79a4a5878f0.tar.gz gpgme-8ddb42ada46f00d8393f6c2df7d6b79a4a5878f0.zip |
cpp: Wrap keylist_from_data
* lang/cpp/data.h, lang/cpp/data.cpp (GpgME::Data::toKeys): New.
--
Doing this in data instead of Context is a bit more idiomatic. But
this could also be added to Context.
Diffstat (limited to 'lang/cpp/src/data.cpp')
-rw-r--r-- | lang/cpp/src/data.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index 2cb4fa88..32ca561b 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -25,6 +25,7 @@ #endif #include "data_p.h" +#include "context_p.h" #include <error.h> #include <interfaces/dataprovider.h> @@ -230,3 +231,26 @@ off_t GpgME::Data::seek(off_t offset, int whence) { return gpgme_data_seek(d->data, offset, whence); } + +std::vector<GpgME::Key> GpgME::Data::toKeys(Protocol proto) const +{ + std::vector<GpgME::Key> ret; + if (isNull()) { + return ret; + } + auto ctx = GpgME::Context::createForProtocol(proto); + if (!ctx) { + return ret; + } + + if (gpgme_op_keylist_from_data_start (ctx->impl()->ctx, d->data, 0)) { + return ret; + } + + gpgme_key_t key; + while (!gpgme_op_keylist_next (ctx->impl()->ctx, &key)) { + ret.push_back(GpgME::Key(key, false)); + } + delete ctx; + return ret; +} |