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 
118  void post_init_ctx();
119 
125  std::string need_user_input_passphrase();
126 
131  std::optional<std::string> check_binary_chacksum(std::filesystem::path);
132 
138  void operator()(gpgme_ctx_t _ctx);
139  };
140 
141  using CtxRefHandler =
142  std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
143  CtxRefHandler _ctx_ref = nullptr;
144  bool good_ = true;
145 
146  signals:
151  void SignalNeedUserInputPassphrase();
152 
153  public:
164  static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
165  const char* passphrase_info,
166  int last_was_bad, int fd);
167 
178  static gpgme_error_t custom_passphrase_cb(void* opaque, const char* uid_hint,
179  const char* passphrase_info,
180  int last_was_bad, int fd);
181 
190  static gpgme_error_t test_status_cb(void* hook, const char* keyword,
191  const char* args);
192 
198  void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
199 };
200 } // namespace GpgFrontend
201 
202 #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:39
Definition: GpgFunctionObject.h:148
Definition: CoreCommonUtil.cpp:31
Definition: GpgContext.h:46
Definition: GpgContext.h:137