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
37 namespace GpgFrontend {
38
43 struct GpgContextInitArgs {
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
59 class 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
118 struct _ctx_ref_deleter {
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__
GpgFrontend::GpgContext::init_ctx
void init_ctx()
Definition: GpgContext.cpp:145
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:49
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::GpgInfo::AppPath
std::string AppPath
executable binary path of gnupg
Definition: GpgInfo.h:41
GpgFrontend::check_gpg_error
GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err)
Definition: GpgConstants.cpp:55
GpgFrontend::GpgContext::GetInfo
const GpgInfo & GetInfo() const
Get the Info object.
Definition: GpgContext.h:95
GpgFrontend::GpgContext
Definition: GpgContext.h:59
GpgFrontend::GpgContext::SetPassphraseCb
void SetPassphraseCb(gpgme_passphrase_cb_t func) const
Set the Passphrase Cb object.
Definition: GpgContext.cpp:193
GpgFrontend::GpgInfo
Use to record some info about gnupg.
Definition: GpgInfo.h:39
GpgFrontend::GpgContext::GpgContext
GpgContext(const GpgContextInitArgs &args={})
Construct a new Gpg Context object.
Definition: GpgContext.cpp:53
GpgFrontend::GpgContext::_ctx_ref_deleter
Definition: GpgContext.h:118
GpgFrontend::GpgContextInitArgs
Definition: GpgContext.h:43
GpgFrontend::check_gpg_error_2_err_code
GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t predict=GPG_ERR_NO_ERROR)
Definition: GpgConstants.cpp:64
GpgFrontend::GpgContext::test_status_cb
static gpgme_error_t test_status_cb(void *hook, const char *keyword, const char *args)
Definition: GpgContext.cpp:221
GpgFrontend::GpgContext::test_passphrase_cb
static gpgme_error_t test_passphrase_cb(void *opaque, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd)
Definition: GpgContext.cpp:204
GpgFrontend::GpgContext::good
bool good() const
Definition: GpgContext.cpp:191