Checking comments

This commit is contained in:
manzerbredes 2015-03-12 20:59:12 +04:00
parent 6fcf2131d3
commit 80f1e1ce67
2 changed files with 46 additions and 33 deletions

View file

@ -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();
}