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 
55  GpgContextInitArgs() = default;
56 };
57 
62 class GPGFRONTEND_CORE_EXPORT GpgContext
63  : public QObject,
64  public SingletonFunctionObject<GpgContext> {
65  Q_OBJECT
66  public:
72  explicit GpgContext(const GpgContextInitArgs& args = {});
73 
79  explicit GpgContext(int channel);
80 
85  ~GpgContext() override = default;
86 
93  [[nodiscard]] bool good() const;
94 
100  [[nodiscard]] const GpgInfo& GetInfo(bool refresh = false);
101 
107  operator gpgme_ctx_t() const { return _ctx_ref.get(); }
108 
109  private:
110  GpgInfo info_{};
111  GpgContextInitArgs args_{};
112  bool extend_info_loaded_ = false;
113  std::shared_mutex preload_lock_{};
114 
119  void post_init_ctx();
120 
126  std::string need_user_input_passphrase();
127 
132  std::optional<std::string> check_binary_chacksum(std::filesystem::path);
133 
139  void operator()(gpgme_ctx_t _ctx);
140  };
141 
142  using CtxRefHandler =
143  std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
144  CtxRefHandler _ctx_ref = nullptr;
145  bool good_ = true;
146 
147  signals:
152  void SignalNeedUserInputPassphrase();
153 
154  public:
165  static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
166  const char* passphrase_info,
167  int last_was_bad, int fd);
168 
179  static gpgme_error_t custom_passphrase_cb(void* opaque, const char* uid_hint,
180  const char* passphrase_info,
181  int last_was_bad, int fd);
182 
191  static gpgme_error_t test_status_cb(void* hook, const char* keyword,
192  const char* args);
193 
199  void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
200 };
201 } // namespace GpgFrontend
202 
203 #endif // __SGPGMEPP_CONTEXT_H__
Definition: GpgContext.h:64
~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:138