diff --git a/src/Nazara/Core/AbstractHash.cpp b/src/Nazara/Core/AbstractHash.cpp index f0e82bb19..60f2f42cb 100644 --- a/src/Nazara/Core/AbstractHash.cpp +++ b/src/Nazara/Core/AbstractHash.cpp @@ -17,8 +17,24 @@ namespace Nz { + /*! + * \class Nz::AbstractHash + * \brief Core class that represents the behaviour of the hash classes + * + * \remark This class is abstract + */ + AbstractHash::~AbstractHash() = default; + /*! + * \brief Factory of Hash classes in function of HashType + * \return A new instance of the Hash class according to the HashType + * + * \param type Enumeration of type HashType + * + * \remark If enumeration is not defined in HashType, a NazaraInternalError is thrown and nullptr is returned + */ + std::unique_ptr AbstractHash::Get(HashType type) { NazaraAssert(type <= HashType_Max, "Hash type value out of enum"); @@ -26,34 +42,34 @@ namespace Nz switch (type) { case HashType_Fletcher16: - return std::unique_ptr(new HashFletcher16); + return std::make_unique(); case HashType_CRC32: - return std::unique_ptr(new HashCRC32); + return std::make_unique(); case HashType_MD5: - return std::unique_ptr(new HashMD5); + return std::make_unique(); case HashType_SHA1: - return std::unique_ptr(new HashSHA1); + return std::make_unique(); case HashType_SHA224: - return std::unique_ptr(new HashSHA224); + return std::make_unique(); case HashType_SHA256: - return std::unique_ptr(new HashSHA256); + return std::make_unique(); case HashType_SHA384: - return std::unique_ptr(new HashSHA384); + return std::make_unique(); case HashType_SHA512: - return std::unique_ptr(new HashSHA512); + return std::make_unique(); case HashType_Whirlpool: - return std::unique_ptr(new HashWhirlpool); + return std::make_unique(); } NazaraInternalError("Hash type not handled (0x" + String::Number(type, 16) + ')'); - return std::unique_ptr(); + return nullptr; } } diff --git a/tests/Engine/Core/AbstractHash.cpp b/tests/Engine/Core/AbstractHash.cpp new file mode 100644 index 000000000..bcb47fc33 --- /dev/null +++ b/tests/Engine/Core/AbstractHash.cpp @@ -0,0 +1,27 @@ +#include +#include + +#include + +#include + +SCENARIO("AbstractHash", "[CORE][ABSTRACTHASH]") +{ + GIVEN("The hash SHA512") + { + std::unique_ptr SHA512 = Nz::AbstractHash::Get(Nz::HashType_SHA512); + SHA512->Begin(); + + WHEN("We introduce data") + { + std::array array{ 0, 1, 2, 3 }; + SHA512->Append(array.begin(), array.size()); + + THEN("We ask for the bytearray") + { + Nz::ByteArray byteArray = SHA512->End(); + REQUIRE(byteArray.GetSize() == SHA512->GetDigestLength()); + } + } + } +}