diff options
Diffstat (limited to 'src/core/function/gpg/GpgKeyManager.h')
-rw-r--r-- | src/core/function/gpg/GpgKeyManager.h | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/src/core/function/gpg/GpgKeyManager.h b/src/core/function/gpg/GpgKeyManager.h index 62f7baca..8b4d41b2 100644 --- a/src/core/function/gpg/GpgKeyManager.h +++ b/src/core/function/gpg/GpgKeyManager.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Saturneric + * Copyright (C) 2021 Saturneric <[email protected]> * * This file is part of GpgFrontend. * @@ -20,21 +20,19 @@ * the gpg4usb project, which is under GPL-3.0-or-later. * * All the source code of GpgFrontend was modified and released by - * Saturneric<[email protected]> starting on May 12, 2021. + * Saturneric <[email protected]> starting on May 12, 2021. * * SPDX-License-Identifier: GPL-3.0-or-later * */ -#ifndef GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H -#define GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H +#pragma once #include <functional> -#include <string> -#include "core/GpgContext.h" -#include "core/GpgFunctionObject.h" -#include "core/GpgModel.h" +#include "core/function/basic/GpgFunctionObject.h" +#include "core/function/gpg/GpgContext.h" +#include "core/typedef/GpgTypedef.h" namespace GpgFrontend { @@ -60,8 +58,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager * @param expires expire date and time of the signature * @return if successful */ - bool SignKey(const GpgKey& target, KeyArgsList& keys, const std::string& uid, - const std::unique_ptr<boost::posix_time::ptime>& expires); + auto SignKey(const GpgKey& target, KeyArgsList& keys, const QString& uid, + const std::unique_ptr<QDateTime>& expires) -> bool; /** * @brief @@ -71,8 +69,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager * @return true * @return false */ - bool RevSign(const GpgFrontend::GpgKey& key, - const GpgFrontend::SignIdArgsListPtr& signature_id); + auto RevSign(const GpgFrontend::GpgKey& key, + const GpgFrontend::SignIdArgsListPtr& signature_id) -> bool; /** * @brief Set the Expire object @@ -83,21 +81,21 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager * @return true * @return false */ - bool SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey, - std::unique_ptr<boost::posix_time::ptime>& expires); + auto SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey, + std::unique_ptr<QDateTime>& expires) -> bool; /** * @brief * * @return */ - bool SetOwnerTrustLevel(const GpgKey& key, int trust_level); + auto SetOwnerTrustLevel(const GpgKey& key, int trust_level) -> bool; private: - static gpgme_error_t interactor_cb_fnc(void* handle, const char* status, - const char* args, int fd); + static auto interactor_cb_fnc(void* handle, const char* status, + const char* args, int fd) -> gpgme_error_t; - using Command = std::string; + using Command = QString; using AutomatonState = enum { AS_START, AS_COMMAND, @@ -113,35 +111,37 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager using AutomatonActionHandler = std::function<Command(AutomatonHandelStruct&, AutomatonState)>; using AutomatonNextStateHandler = - std::function<AutomatonState(AutomatonState, std::string, std::string)>; + std::function<AutomatonState(AutomatonState, QString, QString)>; struct AutomatonHandelStruct { void SetStatus(AutomatonState next_state) { current_state_ = next_state; } - AutomatonState CuurentStatus() { return current_state_; } + auto CuurentStatus() -> AutomatonState { return current_state_; } void SetHandler(AutomatonNextStateHandler next_state_handler, AutomatonActionHandler action_handler) { - next_state_handler_ = next_state_handler; - action_handler_ = action_handler; + next_state_handler_ = std::move(next_state_handler); + action_handler_ = std::move(action_handler); } - AutomatonState NextState(std::string gpg_status, std::string args) { - return next_state_handler_(current_state_, gpg_status, args); + auto NextState(QString gpg_status, QString args) -> AutomatonState { + return next_state_handler_(current_state_, std::move(gpg_status), + std::move(args)); } - Command Action() { return action_handler_(*this, current_state_); } + auto Action() -> Command { return action_handler_(*this, current_state_); } void SetSuccess(bool success) { success_ = success; } - bool Success() { return success_; } + [[nodiscard]] auto Success() const -> bool { return success_; } - std::string KeyFpr() { return key_fpr_; } + auto KeyFpr() -> QString { return key_fpr_; } - AutomatonHandelStruct(std::string key_fpr) : key_fpr_(key_fpr) {} + explicit AutomatonHandelStruct(QString key_fpr) + : key_fpr_(std::move(key_fpr)) {} private: AutomatonState current_state_ = AS_START; AutomatonNextStateHandler next_state_handler_; AutomatonActionHandler action_handler_; bool success_ = false; - std::string key_fpr_; + QString key_fpr_; }; GpgContext& ctx_ = @@ -149,5 +149,3 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager }; } // namespace GpgFrontend - -#endif // GPGFRONTEND_ZH_CN_TS_GPGKEYMANAGER_H |