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 <optional>
33 #include <string>
34
35 #include "GpgFunctionObject.h"
36 #include "GpgInfo.h"
37
38 namespace GpgFrontend {
39
44 struct GpgContextInitArgs {
45 // make no sense for gpg2
46 bool independent_database = false;
47 std::string db_path = {};
48
49 bool gpg_alone = false;
50 std::string gpg_path = {};
51
52 bool test_mode = false;
53 bool ascii = true;
54 bool offline_mode = false;
55 bool auto_import_missing_key = false;
56
57 bool custom_gpgconf = false;
58 std::string custom_gpgconf_path;
59
60 bool use_pinentry = false;
61
62 GpgContextInitArgs() = default;
63 };
64
69 class GPGFRONTEND_CORE_EXPORT GpgContext
70 : public QObject,
71 public SingletonFunctionObject<GpgContext> {
72 Q_OBJECT
73 public:
79 explicit GpgContext(const GpgContextInitArgs& args = {});
80
86 explicit GpgContext(int channel);
87
92 ~GpgContext() override = default;
93
100 [[nodiscard]] bool good() const;
101
107 [[nodiscard]] const GpgInfo& GetInfo(bool refresh = false);
108
114 operator gpgme_ctx_t() const { return _ctx_ref.get(); }
115
116 private:
117 GpgInfo info_{};
118 GpgContextInitArgs args_{};
119 bool extend_info_loaded_ = false;
120 std::shared_mutex preload_lock_{};
121
126 void post_init_ctx();
127
133 std::string need_user_input_passphrase();
134
139 std::optional<std::string> check_binary_chacksum(std::filesystem::path);
140
145 struct _ctx_ref_deleter {
146 void operator()(gpgme_ctx_t _ctx);
147 };
148
149 using CtxRefHandler =
150 std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
151 CtxRefHandler _ctx_ref = nullptr;
152 bool good_ = true;
153
154 signals:
159 void SignalNeedUserInputPassphrase();
160
161 public:
172 static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
173 const char* passphrase_info,
174 int last_was_bad, int fd);
175
186 static gpgme_error_t custom_passphrase_cb(void* opaque, const char* uid_hint,
187 const char* passphrase_info,
188 int last_was_bad, int fd);
189
198 static gpgme_error_t test_status_cb(void* hook, const char* keyword,
199 const char* args);
200
206 void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
207 };
208 } // namespace GpgFrontend
209
210 #endif // __SGPGMEPP_CONTEXT_H__
GpgFrontend::GpgContext
Definition: GpgContext.h:71
GpgFrontend::GpgContext::~GpgContext
~GpgContext() override=default
Destroy the Gpg Context object.
GpgFrontend::GpgInfo
Use to record some info about gnupg.
Definition: GpgInfo.h:40
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:150
GpgFrontend
Definition: CoreCommonUtil.cpp:31
GpgFrontend::GpgContextInitArgs
Definition: GpgContext.h:44
GpgFrontend::GpgContext::_ctx_ref_deleter
Definition: GpgContext.h:145