aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/gpg/GpgAutomatonHandler.h
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-11-26 22:04:00 +0000
committersaturneric <[email protected]>2024-11-26 22:07:04 +0000
commitaf776283bd5d50363c8777dbb3524fde417cc368 (patch)
treea633e2e8161dc7b9048af25d81e284c116e217cc /src/core/function/gpg/GpgAutomatonHandler.h
parentfeat: support eml data decryption (diff)
downloadGpgFrontend-af776283bd5d50363c8777dbb3524fde417cc368.tar.gz
GpgFrontend-af776283bd5d50363c8777dbb3524fde417cc368.zip
feat: support uid revoke and uid delete operations
Diffstat (limited to 'src/core/function/gpg/GpgAutomatonHandler.h')
-rw-r--r--src/core/function/gpg/GpgAutomatonHandler.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/core/function/gpg/GpgAutomatonHandler.h b/src/core/function/gpg/GpgAutomatonHandler.h
new file mode 100644
index 00000000..075edb82
--- /dev/null
+++ b/src/core/function/gpg/GpgAutomatonHandler.h
@@ -0,0 +1,110 @@
+
+
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * 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.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#include "core/GpgFrontendCore.h"
+#include "core/function/basic/GpgFunctionObject.h"
+#include "core/function/gpg/GpgContext.h"
+#include "core/typedef/GpgTypedef.h"
+
+namespace GpgFrontend {
+
+class GpgAutomatonHandler
+ : public SingletonFunctionObject<GpgAutomatonHandler> {
+ public:
+ using Command = QString;
+ using AutomatonState = enum {
+ AS_START,
+ AS_SELECT,
+ AS_COMMAND,
+ AS_VALUE,
+ AS_REASON_CODE,
+ AS_REASON_TEXT,
+ AS_REALLY_ULTIMATE,
+ AS_SAVE,
+ AS_ERROR,
+ AS_QUIT,
+ };
+
+ struct AutomatonHandelStruct;
+
+ using AutomatonActionHandler =
+ std::function<Command(AutomatonHandelStruct&, AutomatonState)>;
+ using AutomatonNextStateHandler =
+ std::function<AutomatonState(AutomatonState, QString, QString)>;
+
+ struct AutomatonHandelStruct {
+ explicit AutomatonHandelStruct(QString key_fpr);
+ void SetStatus(AutomatonState next_state);
+ auto CurrentStatus() -> AutomatonState;
+ void SetHandler(AutomatonNextStateHandler next_state_handler,
+ AutomatonActionHandler action_handler);
+ auto NextState(QString gpg_status, QString args) -> AutomatonState;
+ auto Action() -> Command;
+ void SetSuccess(bool success);
+ [[nodiscard]] auto Success() const -> bool;
+ auto KeyFpr() -> QString;
+
+ private:
+ AutomatonState current_state_ = AS_START;
+ AutomatonNextStateHandler next_state_handler_;
+ AutomatonActionHandler action_handler_;
+ bool success_ = false;
+ QString key_fpr_;
+ };
+
+ /**
+ * @brief Construct a new Gpg Key Manager object
+ *
+ * @param channel
+ */
+ explicit GpgAutomatonHandler(
+ int channel = SingletonFunctionObject::GetDefaultChannel());
+
+ auto DoInteract(const GpgKey& key,
+ AutomatonNextStateHandler next_state_handler,
+ AutomatonActionHandler action_handler) -> bool;
+
+ private:
+ static auto interator_cb_func(void* handle, const char* status,
+ const char* args, int fd) -> gpgme_error_t;
+
+ GpgContext& ctx_ =
+ GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///<
+};
+
+using AutomatonNextStateHandler =
+ GpgAutomatonHandler::AutomatonNextStateHandler;
+using AutomatonState = GpgAutomatonHandler::AutomatonState;
+using AutomatonActionHandler = GpgAutomatonHandler::AutomatonActionHandler;
+using AutomatonHandelStruct = GpgAutomatonHandler::AutomatonHandelStruct;
+
+} // namespace GpgFrontend \ No newline at end of file