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() const { return info_; }
96 
102  operator gpgme_ctx_t() const { return _ctx_ref.get(); }
103 
104  private:
105  GpgInfo info_;
106  GpgContextInitArgs args_;
107 
112  void init_ctx();
113 
119  void operator()(gpgme_ctx_t _ctx);
120  };
121 
122  using CtxRefHandler =
123  std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
124  CtxRefHandler _ctx_ref = nullptr;
125  bool good_ = true;
126 
127  public:
138  static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
139  const char* passphrase_info,
140  int last_was_bad, int fd);
141 
150  static gpgme_error_t test_status_cb(void* hook, const char* keyword,
151  const char* args);
152 
158  void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
159 };
160 } // namespace GpgFrontend
161 
162 #endif // __SGPGMEPP_CONTEXT_H__
Definition: GpgContext.h:60
const GpgInfo & GetInfo() const
Get the Info object.
Definition: GpgContext.h:95
~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:118