diff options
Diffstat (limited to 'src/core/function/gpg/GpgFileOpera.h')
-rw-r--r-- | src/core/function/gpg/GpgFileOpera.h | 249 |
1 files changed, 199 insertions, 50 deletions
diff --git a/src/core/function/gpg/GpgFileOpera.h b/src/core/function/gpg/GpgFileOpera.h index dc81bc53..d7c2d44c 100644 --- a/src/core/function/gpg/GpgFileOpera.h +++ b/src/core/function/gpg/GpgFileOpera.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Saturneric + * Copyright (C) 2021 Saturneric <[email protected]> * * This file is part of GpgFrontend. * @@ -20,59 +20,123 @@ * 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_GPGFILEOPERA_H -#define GPGFRONTEND_GPGFILEOPERA_H +#pragma once -#include "core/GpgConstants.h" -#include "core/GpgContext.h" -#include "core/GpgModel.h" +#include "core/function/basic/GpgFunctionObject.h" +#include "core/function/gpg/GpgContext.h" +#include "core/function/result_analyse/GpgResultAnalyse.h" +#include "core/typedef/GpgTypedef.h" namespace GpgFrontend { /** - * @brief Executive files related to the basic operations that are provided by - * GpgBasicOperator + * @brief Executive files related to the basic operations of GPG + * * @class class: GpgBasicOperator */ class GPGFRONTEND_CORE_EXPORT GpgFileOpera : public SingletonFunctionObject<GpgFileOpera> { public: + /** + * @brief Construct a new Gpg File Opera object + * + * @param channel + */ explicit GpgFileOpera( int channel = SingletonFunctionObject::GetDefaultChannel()); /** - * @brief Encrypted file + * @brief Encrypted file with public key * * @param keys Used public key * @param in_path The path where the enter file is located * @param out_path The path where the output file is located * @param result Encrypted results - * @param _channel Channel in context + * @param channel Channel in context * @return unsigned int error code */ - static unsigned int EncryptFile(KeyListPtr keys, const std::string& in_path, - const std::string& out_path, - GpgEncrResult& result, - int _channel = GPGFRONTEND_DEFAULT_CHANNEL); + void EncryptFile(const KeyArgsList& keys, const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); + + /** + * @brief + * + * @param keys + * @param in_path + * @param ascii + * @param out_path + * @return std::tuple<GpgError, DataObjectPtr> + */ + auto EncryptFileSync(const KeyArgsList& keys, const QString& in_path, + bool ascii, const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief + * + * @param keys + * @param in_path + * @param ascii + * @param out_path + * @param cb + */ + void EncryptDirectory(const KeyArgsList& keys, const QString& in_path, + bool ascii, const QString& out_path, + const GpgOperationCallback& cb); /** - * @brief 运用对称加密算法加密文件 + * @brief Encrypted file symmetrically (with password) * * @param in_path * @param out_path * @param result - * @param _channel + * @param channel * @return unsigned int */ - static unsigned int EncryptFileSymmetric( - const std::string& in_path, const std::string& out_path, - GpgEncrResult& result, int _channel = GPGFRONTEND_DEFAULT_CHANNEL); + void EncryptFileSymmetric(const QString& in_path, bool ascii, + const QString& out_path, + const GpgOperationCallback& cb); + + /** + * @brief + * + * @param in_path + * @param ascii + * @param out_path + * @param cb + */ + auto EncryptFileSymmetricSync(const QString& in_path, bool ascii, + const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief + * + * @param in_path + * @param ascii + * @param out_path + * @param cb + */ + void EncryptDerectorySymmetric(const QString& in_path, bool ascii, + const QString& out_path, + const GpgOperationCallback& cb); + + /** + * @brief + * + * @param in_path + * @param ascii + * @param out_path + */ + auto EncryptDerectorySymmetricSync(const QString& in_path, bool ascii, + const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; /** * @brief @@ -82,37 +146,77 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param result * @return GpgError */ - static GpgError DecryptFile(const std::string& in_path, - const std::string& out_path, - GpgDecrResult& result); + void DecryptFile(const QString& in_path, const QString& out_path, + const GpgOperationCallback& cb); /** * @brief * + * @param in_path + * @param out_path + * @param cb + * @return std::tuple<GpgError, DataObjectPtr> + */ + auto DecryptFileSync(const QString& in_path, const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief + * + * @param in_path + * @param out_path + * @param cb + */ + void DecryptArchive(const QString& in_path, const QString& out_path, + const GpgOperationCallback& cb); + + /** + * @brief Sign file with private key + * * @param keys * @param in_path * @param out_path * @param result - * @param _channel + * @param channel + * @return GpgError + */ + void SignFile(const KeyArgsList& keys, const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); + + /** + * @brief + * + * @param keys + * @param in_path + * @param ascii + * @param out_path + * @return std::tuple<GpgError, DataObjectPtr> + */ + auto SignFileSync(const KeyArgsList& keys, const QString& in_path, bool ascii, + const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief Verify file with public key + * + * @param data_path The path where the enter file is located + * @param sign_path The path where the signature file is located + * @param result Verify results + * @param channel Channel in context * @return GpgError */ - static GpgError SignFile(KeyListPtr keys, const std::string& in_path, - const std::string& out_path, GpgSignResult& result, - int _channel = GPGFRONTEND_DEFAULT_CHANNEL); + void VerifyFile(const QString& data_path, const QString& sign_path, + const GpgOperationCallback& cb); /** * @brief * * @param data_path * @param sign_path - * @param result - * @param _channel - * @return GpgError + * @return std::tuple<GpgError, DataObjectPtr> */ - static GpgError VerifyFile(const std::string& data_path, - const std::string& sign_path, - GpgVerifyResult& result, - int _channel = GPGFRONTEND_DEFAULT_CHANNEL); + auto VerifyFileSync(const QString& data_path, const QString& sign_path) + -> std::tuple<GpgError, DataObjectPtr>; /** * @brief @@ -120,18 +224,44 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param keys * @param signer_keys * @param in_path + * @param ascii + * @param out_path + * @param cb + */ + void EncryptSignFile(const KeyArgsList& keys, const KeyArgsList& signer_keys, + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); + + /** + * @brief + * + * @param keys + * @param signer_keys + * @param in_path + * @param ascii * @param out_path - * @param encr_res - * @param sign_res - * @param _channel - * @return GpgError */ - static GpgError EncryptSignFile(KeyListPtr keys, KeyListPtr signer_keys, - const std::string& in_path, - const std::string& out_path, - GpgEncrResult& encr_res, - GpgSignResult& sign_res, - int _channel = GPGFRONTEND_DEFAULT_CHANNEL); + auto EncryptSignFileSync(const KeyArgsList& keys, + const KeyArgsList& signer_keys, + const QString& in_path, bool ascii, + const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief + * + * @param keys + * @param signer_keys + * @param in_path + * @param ascii + * @param out_path + * @param cb + */ + void EncryptSignDirectory(const KeyArgsList& keys, + const KeyArgsList& signer_keys, + const QString& in_path, bool ascii, + const QString& out_path, + const GpgOperationCallback& cb); /** * @brief @@ -142,12 +272,31 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param verify_res * @return GpgError */ - static GpgError DecryptVerifyFile(const std::string& in_path, - const std::string& out_path, - GpgDecrResult& decr_res, - GpgVerifyResult& verify_res); + void DecryptVerifyFile(const QString& in_path, const QString& out_path, + const GpgOperationCallback& cb); + + /** + * @brief + * + * @param in_path + * @param out_path + */ + auto DecryptVerifyFileSync(const QString& in_path, const QString& out_path) + -> std::tuple<GpgError, DataObjectPtr>; + + /** + * @brief + * + * @param in_path + * @param out_path + * @param cb + */ + void DecryptVerifyArchive(const QString& in_path, const QString& out_path, + const GpgOperationCallback& cb); + + private: + GpgContext& ctx_ = GpgContext::GetInstance( + SingletonFunctionObject::GetChannel()); ///< Corresponding context }; } // namespace GpgFrontend - -#endif // GPGFRONTEND_GPGFILEOPERA_H |