diff --git a/GCryptCLI/include/ModuleDataFormatter.h b/GCryptCLI/include/ModuleDataFormatter.h index cd84966..5a5b046 100644 --- a/GCryptCLI/include/ModuleDataFormatter.h +++ b/GCryptCLI/include/ModuleDataFormatter.h @@ -15,13 +15,13 @@ class ModuleDataFormatter { static std::string FormatBlock(const Block& block, const Configuration::IOBASE_FORMAT base); //! Will parse a string of a given iobase to a block - static Block StringToBlock(const std::string& str, const Configuration::IOBASE_FORMAT base); + static Block DecodeFormat(const std::string& str, const Configuration::IOBASE_FORMAT base); //! Will format a vector of blocks to a given iobase static std::string FormatBlocks(const std::vector& blocks, const Configuration::IOBASE_FORMAT base); //! Will format a string making up multiple block in a given iobase into a vector of block - static std::vector StringToBlocks(const std::string& str, const Configuration::IOBASE_FORMAT base); + static std::vector DecodeFormatMultiblock(const std::string& str, const Configuration::IOBASE_FORMAT base); private: diff --git a/GCryptCLI/src/ModuleDataFormatter.cpp b/GCryptCLI/src/ModuleDataFormatter.cpp index bd809bc..a2df716 100644 --- a/GCryptCLI/src/ModuleDataFormatter.cpp +++ b/GCryptCLI/src/ModuleDataFormatter.cpp @@ -89,7 +89,7 @@ std::string ModuleDataFormatter::FormatBlocks( return ss.str(); } -Block ModuleDataFormatter::StringToBlock( +Block ModuleDataFormatter::DecodeFormat( const std::string& str, const Configuration::IOBASE_FORMAT base ) { @@ -163,7 +163,7 @@ Block ModuleDataFormatter::StringToBlock( return b; } -std::vector ModuleDataFormatter::StringToBlocks( +std::vector ModuleDataFormatter::DecodeFormatMultiblock( const std::string& str, const Configuration::IOBASE_FORMAT base ) { @@ -194,7 +194,7 @@ std::vector ModuleDataFormatter::StringToBlocks( const std::string subs = str.substr(i, blockWidth); - Block newBlock = StringToBlock( + Block newBlock = DecodeFormat( subs, base ); @@ -221,7 +221,7 @@ std::vector ModuleDataFormatter::StringToBlocks( i - blockStart ); - Block newBlock = StringToBlock( + Block newBlock = DecodeFormat( subs, base ); diff --git a/GCryptCLI/src/main.cpp b/GCryptCLI/src/main.cpp index 1339ee8..a7c0452 100644 --- a/GCryptCLI/src/main.cpp +++ b/GCryptCLI/src/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char* const* argv) { std::cout << "Formatted: " << formattedBlocks << std::endl << std::endl; const std::vector retrievedBlocks = - ModuleDataFormatter::StringToBlocks( + ModuleDataFormatter::DecodeFormatMultiblock( formattedBlocks, Configuration::iobaseFormat ); @@ -90,7 +90,7 @@ int main(int argc, char* const* argv) { */ std::cout - << ModuleDataFormatter::StringToBlock( + << ModuleDataFormatter::DecodeFormat( ModuleDataFormatter::FormatBlock( ModulePrepareKey::GetKey(), Configuration::iobaseFormat diff --git a/GCryptCLI/test/DataFormatter.cpp b/GCryptCLI/test/DataFormatter.cpp index cfba346..98d4df8 100644 --- a/GCryptCLI/test/DataFormatter.cpp +++ b/GCryptCLI/test/DataFormatter.cpp @@ -1,9 +1,31 @@ -#include "ModuleDataFormatter.h" +#include +#include #include "Catch2.h" using namespace Leonetienne::GCrypt; -// Empty test -TEST_CASE(__FILE__"", "[ModuleDataFormatter]") { +// Tests that recoding byte iobase works +TEST_CASE(__FILE__"RecodingSingleBlock-bytes", "[ModuleDataFormatter]") { + + // Setup + Block b_initial; + b_initial = Key::Random(); + + // Exercise + // Convert to bytes + const std::string b_format = ModuleDataFormatter::FormatBlock( + b_initial, + Configuration::IOBASE_FORMAT::BASE_BYTES + ); + + // Convert back to a block + const Block b_retrieved = ModuleDataFormatter::DecodeFormat( + b_format, + Configuration::IOBASE_FORMAT::BASE_BYTES + ); + + // Verify + // Do b_initial and b_retrieved match? + REQUIRE(b_initial == b_retrieved); }