diff options
Diffstat (limited to 'src/gpg/GpgContext.h')
-rw-r--r-- | src/gpg/GpgContext.h | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/gpg/GpgContext.h b/src/gpg/GpgContext.h index 5812f49f..146f0794 100644 --- a/src/gpg/GpgContext.h +++ b/src/gpg/GpgContext.h @@ -32,34 +32,49 @@ namespace GpgFrontend { +struct GpgContextInitArgs { + // make no sense for gpg2 + bool independent_database = false; + std::string db_path = {}; + bool gpg_alone = false; + std::string gpg_path = {}; + bool test_mode = false; + bool ascii = true; + + GpgContextInitArgs() = default; +}; + /** * Custom Encapsulation of GpgME APIs */ class GpgContext : public SingletonFunctionObject<GpgContext> { public: - explicit GpgContext(bool independent_database = false, - std::string path = std::string(), int channel = 0); + explicit GpgContext(const GpgContextInitArgs& args = {}); + + explicit GpgContext(int channel) + : SingletonFunctionObject<GpgContext>(channel) {} ~GpgContext() override = default; [[nodiscard]] bool good() const; - [[nodiscard]] const GpgInfo& GetInfo() const { return info; } - - static std::string getGpgmeVersion(); + [[nodiscard]] const GpgInfo& GetInfo() const { return info_; } operator gpgme_ctx_t() const { return _ctx_ref.get(); } private: - GpgInfo info; + GpgInfo info_; + GpgContextInitArgs args_; - struct _ctx_ref_deletor { + void init_ctx(); + + struct _ctx_ref_deleter { void operator()(gpgme_ctx_t _ctx) { if (_ctx != nullptr) gpgme_release(_ctx); } }; - using CtxRefHandler = std::unique_ptr<struct gpgme_context, _ctx_ref_deletor>; + using CtxRefHandler = std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>; CtxRefHandler _ctx_ref = nullptr; bool good_ = true; @@ -67,28 +82,12 @@ class GpgContext : public SingletonFunctionObject<GpgContext> { public: static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint, const char* passphrase_info, - int last_was_bad, int fd) { - LOG(INFO) << "test_passphrase_cb Called"; - size_t res; - std::string pass = "abcdefg\n"; - auto pass_len = pass.size(); - - size_t off = 0; - - (void)opaque; - (void)uid_hint; - (void)passphrase_info; - (void)last_was_bad; - - do { - res = gpgme_io_write(fd, &pass[off], pass_len - off); - if (res > 0) off += res; - } while (res > 0 && off != pass_len); + int last_was_bad, int fd); - return off == pass_len ? 0 : gpgme_error_from_errno(errno); - } + static gpgme_error_t test_status_cb(void* hook, const char* keyword, + const char* args); - void SetPassphraseCb(decltype(test_passphrase_cb) func) const; + void SetPassphraseCb(gpgme_passphrase_cb_t func) const; }; } // namespace GpgFrontend |