GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgKeyManager.h
1 
29 #ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H
30 #define GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H
31 
32 #include <functional>
33 #include <string>
34 
35 #include "core/GpgContext.h"
36 #include "core/GpgFunctionObject.h"
37 #include "core/GpgModel.h"
38 
39 namespace GpgFrontend {
40 
45 class GPGFRONTEND_CORE_EXPORT GpgKeyManager
46  : public SingletonFunctionObject<GpgKeyManager> {
47  public:
53  explicit GpgKeyManager(
55 
63  bool SignKey(const GpgKey& target, KeyArgsList& keys, const std::string& uid,
64  const std::unique_ptr<boost::posix_time::ptime>& expires);
65 
74  bool RevSign(const GpgFrontend::GpgKey& key,
75  const GpgFrontend::SignIdArgsListPtr& signature_id);
76 
86  bool SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey,
87  std::unique_ptr<boost::posix_time::ptime>& expires);
88 
94  bool SetOwnerTrustLevel(const GpgKey& key, int trust_level);
95 
96  private:
97  static gpgme_error_t interactor_cb_fnc(void* handle, const char* status,
98  const char* args, int fd);
99 
100  using Command = std::string;
101  using AutomatonState = enum {
102  AS_START,
103  AS_COMMAND,
104  AS_VALUE,
105  AS_REALLY_ULTIMATE,
106  AS_SAVE,
107  AS_ERROR,
108  AS_QUIT,
109  };
110 
111  struct AutomatonHandelStruct;
112 
113  using AutomatonActionHandler =
114  std::function<Command(AutomatonHandelStruct&, AutomatonState)>;
115  using AutomatonNextStateHandler =
116  std::function<AutomatonState(AutomatonState, std::string, std::string)>;
117 
119  void SetStatus(AutomatonState next_state) { current_state_ = next_state; }
120  AutomatonState CuurentStatus() { return current_state_; }
121  void SetHandler(AutomatonNextStateHandler next_state_handler,
122  AutomatonActionHandler action_handler) {
123  next_state_handler_ = next_state_handler;
124  action_handler_ = action_handler;
125  }
126  AutomatonState NextState(std::string gpg_status, std::string args) {
127  return next_state_handler_(current_state_, gpg_status, args);
128  }
129  Command Action() { return action_handler_(*this, current_state_); }
130 
131  void SetSuccess(bool success) { success_ = success; }
132 
133  bool Success() { return success_; }
134 
135  std::string KeyFpr() { return key_fpr_; }
136 
137  AutomatonHandelStruct(std::string key_fpr) : key_fpr_(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  std::string key_fpr_;
145  };
146 
147  GpgContext& ctx_ =
149 };
150 
151 } // namespace GpgFrontend
152 
153 #endif // GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H
Definition: GpgContext.h:71
Definition: GpgKeyManager.h:46
Definition: GpgKey.h:43
Definition: GpgFunctionObject.h:150
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:251
static GpgContext & GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)
Get the Instance object.
Definition: GpgFunctionObject.h:172
int GetChannel() const
Get the Channel object.
Definition: GpgFunctionObject.h:258
Definition: CoreCommonUtil.cpp:31