diff options
author | Saturn&Eric <[email protected]> | 2023-07-13 16:51:19 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-07-13 16:51:19 +0000 |
commit | 40bcaec6c8c0c363bf793745131a2e6d0274fd6d (patch) | |
tree | 8dc11045bee7caf8a1b936ee2203dd39bec59e07 /src/core/function/gpg/GpgKeyManager.h | |
parent | Merge pull request #102 from CDmking/main (diff) | |
parent | Merge branch 'main' into dev/2.1.0/main (diff) | |
download | GpgFrontend-40bcaec6c8c0c363bf793745131a2e6d0274fd6d.tar.gz GpgFrontend-40bcaec6c8c0c363bf793745131a2e6d0274fd6d.zip |
Merge pull request #106 from saturneric/dev/2.1.0/main
Develop 2.1.1.4
Diffstat (limited to 'src/core/function/gpg/GpgKeyManager.h')
-rw-r--r-- | src/core/function/gpg/GpgKeyManager.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/core/function/gpg/GpgKeyManager.h b/src/core/function/gpg/GpgKeyManager.h index 22738594..62f7baca 100644 --- a/src/core/function/gpg/GpgKeyManager.h +++ b/src/core/function/gpg/GpgKeyManager.h @@ -29,6 +29,9 @@ #ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H #define GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H +#include <functional> +#include <string> + #include "core/GpgContext.h" #include "core/GpgFunctionObject.h" #include "core/GpgModel.h" @@ -83,7 +86,64 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager bool SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey, std::unique_ptr<boost::posix_time::ptime>& expires); + /** + * @brief + * + * @return + */ + bool SetOwnerTrustLevel(const GpgKey& key, int trust_level); + private: + static gpgme_error_t interactor_cb_fnc(void* handle, const char* status, + const char* args, int fd); + + using Command = std::string; + using AutomatonState = enum { + AS_START, + AS_COMMAND, + AS_VALUE, + AS_REALLY_ULTIMATE, + AS_SAVE, + AS_ERROR, + AS_QUIT, + }; + + struct AutomatonHandelStruct; + + using AutomatonActionHandler = + std::function<Command(AutomatonHandelStruct&, AutomatonState)>; + using AutomatonNextStateHandler = + std::function<AutomatonState(AutomatonState, std::string, std::string)>; + + struct AutomatonHandelStruct { + void SetStatus(AutomatonState next_state) { current_state_ = next_state; } + AutomatonState CuurentStatus() { return current_state_; } + void SetHandler(AutomatonNextStateHandler next_state_handler, + AutomatonActionHandler action_handler) { + next_state_handler_ = next_state_handler; + action_handler_ = action_handler; + } + AutomatonState NextState(std::string gpg_status, std::string args) { + return next_state_handler_(current_state_, gpg_status, args); + } + Command Action() { return action_handler_(*this, current_state_); } + + void SetSuccess(bool success) { success_ = success; } + + bool Success() { return success_; } + + std::string KeyFpr() { return key_fpr_; } + + AutomatonHandelStruct(std::string key_fpr) : key_fpr_(key_fpr) {} + + private: + AutomatonState current_state_ = AS_START; + AutomatonNextStateHandler next_state_handler_; + AutomatonActionHandler action_handler_; + bool success_ = false; + std::string key_fpr_; + }; + GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< }; |