GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgKeyManager.h
1 
29 #pragma once
30 
31 #include <functional>
32 
33 #include "core/function/basic/GpgFunctionObject.h"
34 #include "core/function/gpg/GpgContext.h"
35 #include "core/typedef/GpgTypedef.h"
36 
37 namespace GpgFrontend {
38 
43 class GPGFRONTEND_CORE_EXPORT GpgKeyManager
44  : public SingletonFunctionObject<GpgKeyManager> {
45  public:
51  explicit GpgKeyManager(
53 
61  auto SignKey(const GpgKey& target, KeyArgsList& keys, const QString& uid,
62  const std::unique_ptr<QDateTime>& expires) -> bool;
63 
72  auto RevSign(const GpgFrontend::GpgKey& key,
73  const GpgFrontend::SignIdArgsListPtr& signature_id) -> bool;
74 
84  auto SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey,
85  std::unique_ptr<QDateTime>& expires) -> bool;
86 
92  auto SetOwnerTrustLevel(const GpgKey& key, int trust_level) -> bool;
93 
94  private:
95  static auto interactor_cb_fnc(void* handle, const char* status,
96  const char* args, int fd) -> gpgme_error_t;
97 
98  using Command = QString;
99  using AutomatonState = enum {
100  AS_START,
101  AS_COMMAND,
102  AS_VALUE,
103  AS_REALLY_ULTIMATE,
104  AS_SAVE,
105  AS_ERROR,
106  AS_QUIT,
107  };
108 
109  struct AutomatonHandelStruct;
110 
111  using AutomatonActionHandler =
112  std::function<Command(AutomatonHandelStruct&, AutomatonState)>;
113  using AutomatonNextStateHandler =
114  std::function<AutomatonState(AutomatonState, QString, QString)>;
115 
117  void SetStatus(AutomatonState next_state) { current_state_ = next_state; }
118  auto CuurentStatus() -> AutomatonState { return current_state_; }
119  void SetHandler(AutomatonNextStateHandler next_state_handler,
120  AutomatonActionHandler action_handler) {
121  next_state_handler_ = std::move(next_state_handler);
122  action_handler_ = std::move(action_handler);
123  }
124  auto NextState(QString gpg_status, QString args) -> AutomatonState {
125  return next_state_handler_(current_state_, std::move(gpg_status),
126  std::move(args));
127  }
128  auto Action() -> Command { return action_handler_(*this, current_state_); }
129 
130  void SetSuccess(bool success) { success_ = success; }
131 
132  [[nodiscard]] auto Success() const -> bool { return success_; }
133 
134  auto KeyFpr() -> QString { return key_fpr_; }
135 
136  explicit AutomatonHandelStruct(QString key_fpr)
137  : key_fpr_(std::move(key_fpr)) {}
138 
139  private:
140  AutomatonState current_state_ = AS_START;
141  AutomatonNextStateHandler next_state_handler_;
142  AutomatonActionHandler action_handler_;
143  bool success_ = false;
144  QString key_fpr_;
145  };
146 
147  GpgContext& ctx_ =
149 };
150 
151 } // namespace GpgFrontend
Definition: GpgContext.h:58
Definition: GpgKeyManager.h:44
Definition: GpgKey.h:40
Definition: GpgFunctionObject.h:58
auto GetChannel() const -> int
Get the Channel object.
Definition: GpgFunctionObject.h:140
static auto GetInstance(int channel=GpgFrontend::kGpgFrontendDefaultChannel) -> GpgContext &
Get the Instance object.
Definition: GpgFunctionObject.h:80
static auto GetDefaultChannel() -> int
Get the Default Channel object.
Definition: GpgFunctionObject.h:131
Definition: app.cpp:39