From fad87e9944183925fdd119c1936d13dd5fd77dea Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Thu, 26 May 2022 22:06:04 +0200 Subject: [PATCH] Add exceptoins --- GCryptCLI/src/Configuration.cpp | 45 +++++++++++++++++++----------- GCryptCLI/src/ModulePrepareKey.cpp | 3 ++ GCryptCLI/src/main.cpp | 3 ++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/GCryptCLI/src/Configuration.cpp b/GCryptCLI/src/Configuration.cpp index 43c2438..e069503 100644 --- a/GCryptCLI/src/Configuration.cpp +++ b/GCryptCLI/src/Configuration.cpp @@ -10,6 +10,29 @@ void Configuration::Parse() { return; } +void Configuration::DecideModule() { + if (CommandlineInterface::Get().HasParam("--encrypt")) { + activeModule = MODULE::ENCRYPT; + return; + } + else if (CommandlineInterface::Get().HasParam("--decrypt")) { + activeModule = MODULE::DECRYPT; + return; + } + else if (CommandlineInterface::Get().HasParam("--hash")) { + activeModule = MODULE::HASH; + return; + } + else if (CommandlineInterface::Get().HasParam("--generate-keyfile")) { + activeModule = MODULE::GENERATE_KEYFILE; + return; + } + + throw std::runtime_error("No module option found. Is the CLI parser configuration correct?."); + + return; +} + void Configuration::DecideInputFrom() { if (CommandlineInterface::Get().HasParam("--intext")) { @@ -46,23 +69,6 @@ void Configuration::DecideOutputTo() { return; } -void Configuration::DecideModule() { - if (CommandlineInterface::Get().HasParam("--encrypt")) { - activeModule = MODULE::ENCRYPT; - } - else if (CommandlineInterface::Get().HasParam("--decrypt")) { - activeModule == MODULE::DECRYPT; - } - else if (CommandlineInterface::Get().HasParam("--hash")) { - activeModule == MODULE::HASH; - } - else if (CommandlineInterface::Get().HasParam("--generate-keyfile")) { - activeModule == MODULE::GENERATE_KEYFILE; - } - - return; -} - void Configuration::DecideIOBaseFormat() { // Do we have any iobase specified? @@ -144,6 +150,11 @@ void Configuration::DecideIOBaseFormat() { return; } + // Fallback: Bytes + else { + iobaseFormat = IOBASE_FORMAT::BASE_BYTES; + } + return; } diff --git a/GCryptCLI/src/ModulePrepareKey.cpp b/GCryptCLI/src/ModulePrepareKey.cpp index 061499b..be7c60f 100644 --- a/GCryptCLI/src/ModulePrepareKey.cpp +++ b/GCryptCLI/src/ModulePrepareKey.cpp @@ -61,6 +61,9 @@ void ModulePrepareKey::PrepareKey() { return; } + throw std::runtime_error("No key option found. Is the CLI parser configuration correct?."); + + return; } diff --git a/GCryptCLI/src/main.cpp b/GCryptCLI/src/main.cpp index ec4fbfb..f5610d7 100644 --- a/GCryptCLI/src/main.cpp +++ b/GCryptCLI/src/main.cpp @@ -14,6 +14,9 @@ int main(int argc, char* const* argv) { // Prepare the key ModulePrepareKey::PrepareKey(); + std::cout << ModulePrepareKey::GetKey().ToHexString() << std::endl; + + return 0; }