GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgContext.h
1
29#ifndef __SGPGMEPP_CONTEXT_H__
30#define __SGPGMEPP_CONTEXT_H__
31
32#include "GpgConstants.h"
33#include "GpgFunctionObject.h"
34#include "GpgInfo.h"
35#include "GpgModel.h"
36
37namespace GpgFrontend {
38
44 // make no sense for gpg2
45 bool independent_database = false;
46 std::string db_path = {};
47 bool gpg_alone = false;
48 std::string gpg_path = {};
49 bool test_mode = false;
50 bool ascii = true;
51
52 GpgContextInitArgs() = default;
53};
54
59class GPGFRONTEND_CORE_EXPORT GpgContext
60 : public SingletonFunctionObject<GpgContext> {
61 public:
67 explicit GpgContext(const GpgContextInitArgs& args = {});
68
74 explicit GpgContext(int channel);
75
80 ~GpgContext() override = default;
81
88 [[nodiscard]] bool good() const;
89
95 [[nodiscard]] const GpgInfo& GetInfo() const { return info_; }
96
102 operator gpgme_ctx_t() const { return _ctx_ref.get(); }
103
104 private:
105 GpgInfo info_;
106 GpgContextInitArgs args_;
107
112 void init_ctx();
113
119 void operator()(gpgme_ctx_t _ctx) {
120 if (_ctx != nullptr) gpgme_release(_ctx);
121 }
122 };
123
124 using CtxRefHandler =
125 std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
126 CtxRefHandler _ctx_ref = nullptr;
127 bool good_ = true;
128
129 public:
140 static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
141 const char* passphrase_info,
142 int last_was_bad, int fd);
143
152 static gpgme_error_t test_status_cb(void* hook, const char* keyword,
153 const char* args);
154
160 void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
161};
162} // namespace GpgFrontend
163
164#endif // __SGPGMEPP_CONTEXT_H__
Definition: GpgContext.h:60
const GpgInfo & GetInfo() const
Get the Info object.
Definition: GpgContext.h:95
~GpgContext() override=default
Destroy the Gpg Context object.
Use to record some info about gnupg.
Definition: GpgInfo.h:39
Definition: GpgFunctionObject.h:49
Definition: CoreCommonUtil.cpp:29
Definition: GpgContext.h:43
Definition: GpgContext.h:118