GpgContext.h
#ifndef __SGPGMEPP_CONTEXT_H__
#define __SGPGMEPP_CONTEXT_H__
#include "GpgConstants.h"
#include "GpgFunctionObject.h"
#include "GpgInfo.h"
#include "GpgModel.h"
namespace GpgFrontend {
struct GpgContextInitArgs {
// make no sense for gpg2
bool independent_database = false;
std::string db_path = {};
bool gpg_alone = false;
std::string gpg_path = {};
bool test_mode = false;
bool ascii = true;
GpgContextInitArgs() = default;
};
class GPGFRONTEND_CORE_EXPORT GpgContext
: public SingletonFunctionObject<GpgContext> {
public:
explicit GpgContext(const GpgContextInitArgs& args = {});
explicit GpgContext(int channel);
~GpgContext() override = default;
[[nodiscard]] bool good() const;
[[nodiscard]] const GpgInfo& GetInfo() const { return info_; }
operator gpgme_ctx_t() const { return _ctx_ref.get(); }
private:
GpgInfo info_;
GpgContextInitArgs args_;
void init_ctx();
struct _ctx_ref_deleter {
void operator()(gpgme_ctx_t _ctx);
};
using CtxRefHandler =
std::unique_ptr<struct gpgme_context, _ctx_ref_deleter>;
CtxRefHandler _ctx_ref = nullptr;
bool good_ = true;
public:
static gpgme_error_t test_passphrase_cb(void* opaque, const char* uid_hint,
const char* passphrase_info,
int last_was_bad, int fd);
static gpgme_error_t test_status_cb(void* hook, const char* keyword,
const char* args);
void SetPassphraseCb(gpgme_passphrase_cb_t func) const;
};
} // namespace GpgFrontend
#endif // __SGPGMEPP_CONTEXT_H__
GpgFrontend::GpgContext::init_ctx
void init_ctx()
Definition: GpgContext.cpp:145
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:148
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::GpgInfo::AppPath
std::string AppPath
executable binary path of gnupg
Definition: GpgInfo.h:41
GpgFrontend::check_gpg_error
GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err)
Definition: GpgConstants.cpp:54
GpgFrontend::GpgContext::GetInfo
const GpgInfo & GetInfo() const
Get the Info object.
Definition: GpgContext.h:95
GpgFrontend::GpgContext
Definition: GpgContext.h:59
GpgFrontend::GpgContext::SetPassphraseCb
void SetPassphraseCb(gpgme_passphrase_cb_t func) const
Set the Passphrase Cb object.
Definition: GpgContext.cpp:193
GpgFrontend::GpgInfo
Use to record some info about gnupg.
Definition: GpgInfo.h:39
GpgFrontend::GpgContext::GpgContext
GpgContext(const GpgContextInitArgs &args={})
Construct a new Gpg Context object.
Definition: GpgContext.cpp:53
GpgFrontend::GpgContext::_ctx_ref_deleter
Definition: GpgContext.h:118
GpgFrontend::GpgContextInitArgs
Definition: GpgContext.h:43
GpgFrontend::check_gpg_error_2_err_code
GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t predict=GPG_ERR_NO_ERROR)
Definition: GpgConstants.cpp:63
GpgFrontend::GpgContext::test_status_cb
static gpgme_error_t test_status_cb(void *hook, const char *keyword, const char *args)
Definition: GpgContext.cpp:221
GpgFrontend::GpgContext::test_passphrase_cb
static gpgme_error_t test_passphrase_cb(void *opaque, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd)
Definition: GpgContext.cpp:204
GpgFrontend::GpgContext::good
bool good() const
Definition: GpgContext.cpp:191