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 
51  bool gpg_alone = false;
52  std::string gpg_path = {};
53 
54  bool test_mode = false;
55  bool ascii = true;
56  bool offline_mode = false;
57  bool auto_import_missing_key = false;
58 
59  bool custom_gpgconf = false;
60  std::string custom_gpgconf_path;
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 
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__
Definition: GpgContext.h:71
~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:145