stringapi: Accept strings when MD5 hashing data

This commit is contained in:
Ben Boeckel 2014-02-07 15:06:13 -05:00 committed by Brad King
parent 473ca1ac4a
commit 77f60392d9
4 changed files with 11 additions and 11 deletions

View File

@ -35,18 +35,18 @@ cmsys::auto_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo)
}
//----------------------------------------------------------------------------
std::string cmCryptoHash::HashString(const char* input)
std::string cmCryptoHash::HashString(const std::string& input)
{
this->Initialize();
this->Append(reinterpret_cast<unsigned char const*>(input),
static_cast<int>(strlen(input)));
this->Append(reinterpret_cast<unsigned char const*>(&input[0]),
static_cast<int>(input.size()));
return this->Finalize();
}
//----------------------------------------------------------------------------
std::string cmCryptoHash::HashFile(const char* file)
std::string cmCryptoHash::HashFile(const std::string& file)
{
cmsys::ifstream fin(file, std::ios::in | cmsys_ios_binary);
cmsys::ifstream fin(file.c_str(), std::ios::in | cmsys_ios_binary);
if(!fin)
{
return "";

View File

@ -21,8 +21,8 @@ class cmCryptoHash
public:
virtual ~cmCryptoHash() {}
static cmsys::auto_ptr<cmCryptoHash> New(const char* algo);
std::string HashString(const char* input);
std::string HashFile(const char* file);
std::string HashString(const std::string& input);
std::string HashFile(const std::string& file);
protected:
virtual void Initialize()=0;
virtual void Append(unsigned char const*, int)=0;

View File

@ -944,7 +944,7 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
#endif
}
bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmCryptoHashMD5 md5;
@ -959,7 +959,7 @@ bool cmSystemTools::ComputeFileMD5(const char* source, char* md5out)
#endif
}
std::string cmSystemTools::ComputeStringMD5(const char* input)
std::string cmSystemTools::ComputeStringMD5(const std::string& input)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmCryptoHashMD5 md5;

View File

@ -185,10 +185,10 @@ public:
static bool RenameFile(const char* oldname, const char* newname);
///! Compute the md5sum of a file
static bool ComputeFileMD5(const char* source, char* md5out);
static bool ComputeFileMD5(const std::string& source, char* md5out);
/** Compute the md5sum of a string. */
static std::string ComputeStringMD5(const char* input);
static std::string ComputeStringMD5(const std::string& input);
/**
* Run a single executable command