Documentation for AbstractHash
Former-commit-id: 467b96c5d8b9ed9a3fddd7cf6f09803977b53caf
This commit is contained in:
parent
08caff5ea3
commit
0934c21967
|
|
@ -17,8 +17,24 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::AbstractHash<T>
|
||||
* \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> 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<AbstractHash>(new HashFletcher16);
|
||||
return std::make_unique<HashFletcher16>();
|
||||
|
||||
case HashType_CRC32:
|
||||
return std::unique_ptr<AbstractHash>(new HashCRC32);
|
||||
return std::make_unique<HashCRC32>();
|
||||
|
||||
case HashType_MD5:
|
||||
return std::unique_ptr<AbstractHash>(new HashMD5);
|
||||
return std::make_unique<HashMD5>();
|
||||
|
||||
case HashType_SHA1:
|
||||
return std::unique_ptr<AbstractHash>(new HashSHA1);
|
||||
return std::make_unique<HashSHA1>();
|
||||
|
||||
case HashType_SHA224:
|
||||
return std::unique_ptr<AbstractHash>(new HashSHA224);
|
||||
return std::make_unique<HashSHA224>();
|
||||
|
||||
case HashType_SHA256:
|
||||
return std::unique_ptr<AbstractHash>(new HashSHA256);
|
||||
return std::make_unique<HashSHA256>();
|
||||
|
||||
case HashType_SHA384:
|
||||
return std::unique_ptr<AbstractHash>(new HashSHA384);
|
||||
return std::make_unique<HashSHA384>();
|
||||
|
||||
case HashType_SHA512:
|
||||
return std::unique_ptr<AbstractHash>(new HashSHA512);
|
||||
return std::make_unique<HashSHA512>();
|
||||
|
||||
case HashType_Whirlpool:
|
||||
return std::unique_ptr<AbstractHash>(new HashWhirlpool);
|
||||
return std::make_unique<HashWhirlpool>();
|
||||
}
|
||||
|
||||
NazaraInternalError("Hash type not handled (0x" + String::Number(type, 16) + ')');
|
||||
return std::unique_ptr<AbstractHash>();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
SCENARIO("AbstractHash", "[CORE][ABSTRACTHASH]")
|
||||
{
|
||||
GIVEN("The hash SHA512")
|
||||
{
|
||||
std::unique_ptr<Nz::AbstractHash> SHA512 = Nz::AbstractHash::Get(Nz::HashType_SHA512);
|
||||
SHA512->Begin();
|
||||
|
||||
WHEN("We introduce data")
|
||||
{
|
||||
std::array<Nz::UInt8, 4> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue