diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-03-12 20:59:12 +0400 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-03-12 20:59:12 +0400 |
| commit | 80f1e1ce67332a82f03e092b6b2396b0834efad9 (patch) | |
| tree | 89ea0b1080153b3bd7f2675a0532f95373df6627 | |
| parent | 6fcf2131d319d8c9a7bff67defb83098e4fe5cab (diff) | |
Checking comments
| -rw-r--r-- | CryptClass/HASHCrypt.cpp | 53 | ||||
| -rw-r--r-- | CryptClass/HASHCrypt.hpp | 26 |
2 files changed, 46 insertions, 33 deletions
diff --git a/CryptClass/HASHCrypt.cpp b/CryptClass/HASHCrypt.cpp index cd0dab6..eed9cb5 100644 --- a/CryptClass/HASHCrypt.cpp +++ b/CryptClass/HASHCrypt.cpp @@ -8,13 +8,12 @@ * */ + //----- class ----- #include "HASHCrypt.hpp" - - //Constructor HASHCrypt::HASHCrypt(){ } @@ -25,6 +24,7 @@ HASHCrypt::~HASHCrypt(){ +//Contruct MD5 over 128 bits and put it into digest void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ //Digest size controller @@ -37,6 +37,8 @@ void HASHCrypt::getMD5_128(std::string chain, byte* digest, int size){ } + +//Contruct SHA-256 and put it into digest void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ //Digest size controller @@ -50,27 +52,6 @@ void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ } -//Check the size of the digest -void HASHCrypt::checkDigestSize(int sizeRequired, int size){ - try{ - if(size !=sizeRequired){ - throw this->getInvalidDigestSizeError(sizeRequired, size); - } - - } - catch(std::string erreur){ - std::cerr << erreur <<std::endl; - std::exit(EXIT_FAILURE); - } -} - -//Make the error -std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ - std::ostringstream erreurStream; - erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)"; - return erreurStream.str(); -} - //Compare 2 digest (same size) bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ @@ -96,6 +77,7 @@ bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ } + //Convert digest to string std::string HASHCrypt::digestToString(byte* digest, int size){ @@ -107,3 +89,28 @@ std::string HASHCrypt::digestToString(byte* digest, int size){ return output; } + + + +//Check the size of the digest +void HASHCrypt::checkDigestSize(int sizeRequired, int size){ + try{ + if(size !=sizeRequired){ + throw this->getInvalidDigestSizeError(sizeRequired, size); + } + + } + catch(std::string erreur){ + std::cerr << erreur <<std::endl; + std::exit(EXIT_FAILURE); + } +} + + + +//Make the error +std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ + std::ostringstream erreurStream; + erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)"; + return erreurStream.str(); +} diff --git a/CryptClass/HASHCrypt.hpp b/CryptClass/HASHCrypt.hpp index 2c17d3d..3eafb2f 100644 --- a/CryptClass/HASHCrypt.hpp +++ b/CryptClass/HASHCrypt.hpp @@ -45,27 +45,31 @@ class HASHCrypt{ */ ~HASHCrypt(); + /** * @brief Create an MD5 over 128 bits on a digest array of bytes. * * @param chain : Chain to hash * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param size : Length of digest * * **Warning** digest will be modified. * Digest must be an array of byte with 16 entries + * Invalid size can cause "Segmentation Fault" */ void getMD5_128(std::string chain, byte* digest, int size); + /** * @brief Create an SHA over 256 bits on a digest array of bytes. * * @param chain : Chain to hash * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param size : Length of digest * * **Warning** digest will be modified. * Digest must be an array of byte with 32 entries + * Invalid size can cause "Segmentation Fault" */ void getSHA_256(std::string chain, byte* digest, int size); //Return SHA_256 @@ -73,14 +77,15 @@ class HASHCrypt{ /** * @brief Convert digest to a string of HEX characters * - * @param digest : An array of bytes (8 bits) - * @param size : Length of the array digest + * @param digest : an array of bytes (8 bits) + * @param size : length of digest * - * @return a string of hex digest equivalent + * @return return a string of hex digest equivalent * - * Digest must be an array of byte with 16 entries + * Digest must be an array of byte. */ - std::string digestToString(byte* digest, int size); //Return a string of a digest + std::string digestToString(byte* digest, int size); //Return a string + /** * @brief Compare 2 digest @@ -89,10 +94,11 @@ class HASHCrypt{ * @param digest2 : An array of bytes (8 bits) * @param size : Length of the array digest1 or digest2 * - * @return a boolean if digest1 equals to digest2 + * @return return a boolean (true if digest1 equals to digest2 and false else) * * **Warning** if sizeof(digest1) != sizeof(digest 2) : segmentation fault ! * Compare the two digest. + * */ bool compareDigest(byte* digest1, byte* digest2, int size); @@ -105,7 +111,7 @@ class HASHCrypt{ * @param sizeRequired : Digest size expected * @param size : Given digest size * - * Throw an exception, and stop the programm if + * Throw an exception, and stop the program if * sizeRequired != size * Use getInvalidDigestSizeError method. */ @@ -113,7 +119,7 @@ class HASHCrypt{ /** - * @brief Make and error message. + * @brief Make "invalid digest size" error message. * * @param sizeRequired : Digest size expected * @param size : Given digest size |
