summaryrefslogtreecommitdiff
path: root/src/error.cc
diff options
context:
space:
mode:
authorMichael Raitza <spacefrogg-devel@meterriblecrew.net>2020-07-28 21:08:39 +0200
committerJohn Wiegley <johnw@newartisans.com>2020-10-30 10:08:00 -0700
commitf8e8cc160048cc7032254f1db7548c68571c3409 (patch)
treef9196d0624e1aa88924f4c0d33a767686026eba4 /src/error.cc
parenteaf095ec3b0017f824cdbfe4e9e4bc42331d421a (diff)
downloadfork-ledger-f8e8cc160048cc7032254f1db7548c68571c3409.tar.gz
fork-ledger-f8e8cc160048cc7032254f1db7548c68571c3409.tar.bz2
fork-ledger-f8e8cc160048cc7032254f1db7548c68571c3409.zip
Implement cryptographic access to files using GPGME
Diffstat (limited to 'src/error.cc')
-rw-r--r--src/error.cc17
1 files changed, 13 insertions, 4 deletions
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<char> buf(new char[static_cast<std::size_t>(len) + 1]);
- in.read(buf.get(), static_cast<std::streamsize>(len));
- assert(in.gcount() == static_cast<std::streamsize>(len));
+ in->read(buf.get(), static_cast<std::streamsize>(len));
+ assert(in->gcount() == static_cast<std::streamsize>(len));
buf[static_cast<std::ptrdiff_t>(len)] = '\0';
bool first = true;
@@ -111,6 +119,7 @@ string source_context(const path& file,
out << prefix << p;
}
+ delete(in);
return out.str();
}