diff options
-rw-r--r-- | lang/cpp/src/data.cpp | 14 | ||||
-rw-r--r-- | lang/cpp/src/data.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index 32ca561b..52b8da24 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -254,3 +254,17 @@ std::vector<GpgME::Key> GpgME::Data::toKeys(Protocol proto) const delete ctx; return ret; } + +std::string GpgME::Data::toString() +{ + std::string ret; + char buf[4096]; + size_t nread; + seek (0, SEEK_SET); + while ((nread = read (buf, 4096)) > 0) + { + ret += std::string (buf, nread); + } + seek (0, SEEK_SET); + return ret; +} diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h index cc7906fb..446f6fa3 100644 --- a/lang/cpp/src/data.h +++ b/lang/cpp/src/data.h @@ -114,6 +114,9 @@ public: * Protocol proto. Returns an empty list on error.*/ std::vector<Key> toKeys(const Protocol proto = Protocol::OpenPGP) const; + /** Return a copy of the data as std::string. Sets seek pos to 0 */ + std::string toString(); + class Private; Private *impl() { |