From f8e8cc160048cc7032254f1db7548c68571c3409 Mon Sep 17 00:00:00 2001 From: Michael Raitza Date: Tue, 28 Jul 2020 21:08:39 +0200 Subject: Implement cryptographic access to files using GPGME --- src/error.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/error.cc') diff --git a/src/error.cc b/src/error.cc index 837d7499..ab7fab5b 100644 --- a/src/error.cc +++ b/src/error.cc @@ -33,6 +33,10 @@ #include "utils.h" +#if HAVE_GPGME +#include "gpgme.h" +#endif + namespace ledger { std::ostringstream _ctxt_buffer; @@ -92,12 +96,16 @@ string source_context(const path& file, std::ostringstream out; - ifstream in(file); - in.seekg(pos, std::ios::beg); +#if HAVE_GPGME + std::istream* in(decrypted_stream_t::open_stream(file)); +#else + std::istream* in(new ifstream(file)); +#endif + in->seekg(pos, std::ios::beg); scoped_array buf(new char[static_cast(len) + 1]); - in.read(buf.get(), static_cast(len)); - assert(in.gcount() == static_cast(len)); + in->read(buf.get(), static_cast(len)); + assert(in->gcount() == static_cast(len)); buf[static_cast(len)] = '\0'; bool first = true; @@ -111,6 +119,7 @@ string source_context(const path& file, out << prefix << p; } + delete(in); return out.str(); } -- cgit v1.2.3