From 93be4d9cdc1fb921c3fab90778dbc4fa1edce1b5 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Fri, 27 May 2022 17:04:16 +0200 Subject: [PATCH] Implement GenerateKeyfile module --- GCryptCLI/include/ModuleGenerateKeyfile.h | 14 ++++++++++++++ GCryptCLI/src/ModuleGenerateKeyfile.cpp | 17 +++++++++++++++++ GCryptCLI/src/main.cpp | 7 +++++++ 3 files changed, 38 insertions(+) create mode 100644 GCryptCLI/include/ModuleGenerateKeyfile.h create mode 100644 GCryptCLI/src/ModuleGenerateKeyfile.cpp diff --git a/GCryptCLI/include/ModuleGenerateKeyfile.h b/GCryptCLI/include/ModuleGenerateKeyfile.h new file mode 100644 index 0000000..eaf5cef --- /dev/null +++ b/GCryptCLI/include/ModuleGenerateKeyfile.h @@ -0,0 +1,14 @@ +#ifndef GCRYPTCLI_MODULE_GENERATEKEYFILE_H +#define GCRYPTCLI_MODULE_GENERATEKEYFILE_H + +namespace Module { + // This class has the task to prepare and supply the encryption key. + class GenerateKeyfile { + public: + //! Will write the key to a file + static void Run(); + }; +} + +#endif + diff --git a/GCryptCLI/src/ModuleGenerateKeyfile.cpp b/GCryptCLI/src/ModuleGenerateKeyfile.cpp new file mode 100644 index 0000000..2b4cd6d --- /dev/null +++ b/GCryptCLI/src/ModuleGenerateKeyfile.cpp @@ -0,0 +1,17 @@ +#include "ModuleGenerateKeyfile.h" + +#include "KeyManager.h" +#include "CommandlineInterface.h" + +using namespace Leonetienne::GCrypt; +using namespace Module; + +void GenerateKeyfile::Run() { + + KeyManager::GetKey().WriteToFile( + CommandlineInterface::Get()["--generate-keyfile"].GetString() + ); + + return; +} + diff --git a/GCryptCLI/src/main.cpp b/GCryptCLI/src/main.cpp index af8f449..2d851b4 100644 --- a/GCryptCLI/src/main.cpp +++ b/GCryptCLI/src/main.cpp @@ -1,6 +1,7 @@ #include "CommandlineInterface.h" #include "Configuration.h" #include "KeyManager.h" +#include "ModuleGenerateKeyfile.h" int main(int argc, char* const* argv) { @@ -13,6 +14,12 @@ int main(int argc, char* const* argv) { // Prepare the key KeyManager::PrepareKey(); + // Launch our module + switch (Configuration::activeModule) { + case Configuration::MODULE::GENERATE_KEYFILE: + Module::GenerateKeyfile::Run(); + } + return 0; }