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 "GpgConstants.h"
36 #include "GpgFunctionObject.h"
37 #include "GpgInfo.h"
38 #include "GpgModel.h"
39 
40 namespace GpgFrontend {
41 
47  // make no sense for gpg2
48  bool independent_database = false;
49  std::string db_path = {};
50  bool gpg_alone = false;
51  std::string gpg_path = {};
52  bool test_mode = false;
53  bool ascii = true;
54  bool offline_mode = false;
55  bool auto_import_missing_key = false;
56 
57  GpgContextInitArgs() = default;
58 };
59 
64 class GPGFRONTEND_CORE_EXPORT GpgContext
65  : public QObject,
66  public SingletonFunctionObject<GpgContext> {
67  Q_OBJECT
68  public:
74  explicit GpgContext(const GpgContextInitArgs& args = {});
75 
81  explicit GpgContext(int channel);
82 
87  ~GpgContext() override = default;
88 
95  [[nodiscard]] bool good() const;
96 
102  [[nodiscard]] const GpgInfo& GetInfo(bool refresh = false);
103 
109  operator gpgme_ctx_t() const { return _ctx_ref.get(); }
110 
111  private:
112  GpgInfo info_{};
113  GpgContextInitArgs args_{};
114  bool extend_info_loaded_ = false;
115  std::shared_mutex preload_lock_{};
116 
121  void post_init_ctx();
122 
128  std::string need_user_input_passphrase();
129 
134  std::optional<std::string> check_binary_chacksum(std::filesystem::path);
135 
141  void operator()(gpgme_ctx_t _ctx);
142  };
143 
144  using CtxRefHandler =
145  std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
146  CtxRefHandler _ctx_ref = nullptr;
147  bool good_ = true;
148 
149  signals:
154  void SignalNeedUserInputPassphrase();
155 
156  public:
167  static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
168  const char* passphrase_info,
169  int last_was_bad, int fd);
170 
181  static gpgme_error_t custom_passphrase_cb(void* opaque, const char* uid_hint,
182  const char* passphrase_info,
183  int last_was_bad, int fd);
184 
193  static gpgme_error_t test_status_cb(void* hook, const char* keyword,
194  const char* args);
195 
201  void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
202 };
203 } // namespace GpgFrontend
204 
205 #endif // __SGPGMEPP_CONTEXT_H__
Definition: GpgContext.h:66
~GpgContext() override=default
Destroy the Gpg Context object.
Use to record some info about gnupg.
Definition: GpgInfo.h:40
Definition: GpgFunctionObject.h:150
Definition: CoreCommonUtil.cpp:31
Definition: GpgContext.h:46
Definition: GpgContext.h:140