[Pkg-gnupg-commit] [gpgme] 115/132: cpp: Wrap keylist_from_data

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Apr 26 01:01:37 UTC 2017


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

dkg pushed a commit to branch experimental
in repository gpgme.

commit 8ddb42ada46f00d8393f6c2df7d6b79a4a5878f0
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Mar 22 16:38:35 2017 +0100

    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.
---
 NEWS                  |  1 +
 lang/cpp/src/data.cpp | 24 ++++++++++++++++++++++++
 lang/cpp/src/data.h   |  5 +++++
 3 files changed, 30 insertions(+)

diff --git a/NEWS b/NEWS
index 367b718..d03fe80 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ Noteworthy changes in version 1.8.1 (unreleased)
  cpp: GpgGenCardKeyInteractor                       NEW.
  cpp: Subkey::keyGrip                               NEW.
  cpp: Subkey::isDeVs                                NEW.
+ cpp: Data::toKeys                                  NEW.
  qt: CryptoConfig::stringValueList()                NEW.
  py: Context.__init__        EXTENDED: New keyword arg home_dir.
  py: Context.home_dir        NEW.
diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp
index 2cb4fa8..32ca561 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;
+}
diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h
index 50bdf62..cc7906f 100644
--- a/lang/cpp/src/data.h
+++ b/lang/cpp/src/data.h
@@ -24,6 +24,7 @@
 #define __GPGMEPP_DATA_H__
 
 #include "global.h"
+#include "key.h"
 
 #include <sys/types.h> // for size_t, off_t
 #include <cstdio> // FILE
@@ -109,6 +110,10 @@ public:
     ssize_t write(const void *buffer, size_t length);
     off_t seek(off_t offset, int whence);
 
+    /** Try to parse the data to a key object using the
+     * Protocol proto. Returns an empty list on error.*/
+    std::vector<Key> toKeys(const Protocol proto = Protocol::OpenPGP) const;
+
     class Private;
     Private *impl()
     {

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