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 "GpgConstants.h"
33 #include "GpgFunctionObject.h"
34 #include "GpgInfo.h"
35 #include "GpgModel.h"
36 
37 namespace GpgFrontend {
38 
44  // make no sense for gpg2
45  bool independent_database = false;
46  std::string db_path = {};
47  bool gpg_alone = false;
48  std::string gpg_path = {};
49  bool test_mode = false;
50  bool ascii = true;
51 
52  GpgContextInitArgs() = default;
53 };
54 
59 class GPGFRONTEND_CORE_EXPORT GpgContext
60  : public SingletonFunctionObject<GpgContext> {
61  public:
67  explicit GpgContext(const GpgContextInitArgs& args = {});
68 
74  explicit GpgContext(int channel);
75 
80  ~GpgContext() override = default;
81 
88  [[nodiscard]] bool good() const;
89 
95  [[nodiscard]] const GpgInfo& GetInfo(bool refresh = false);
96 
102  operator gpgme_ctx_t() const { return _ctx_ref.get(); }
103 
104  private:
105  GpgInfo info_;
106  GpgContextInitArgs args_;
107  bool extend_info_loaded_ = false;
108 
113  void init_ctx();
114 
120  void operator()(gpgme_ctx_t _ctx);
121  };
122 
123  using CtxRefHandler =
124  std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
125  CtxRefHandler _ctx_ref = nullptr;
126  bool good_ = true;
127 
128  public:
139  static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
140  const char* passphrase_info,
141  int last_was_bad, int fd);
142 
151  static gpgme_error_t test_status_cb(void* hook, const char* keyword,
152  const char* args);
153 
159  void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
160 };
161 } // namespace GpgFrontend
162 
163 #endif // __SGPGMEPP_CONTEXT_H__
Definition: GpgContext.h:60
~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:29
Definition: GpgContext.h:43
Definition: GpgContext.h:119