summaryrefslogtreecommitdiffstats
path: root/Source/cmCryptoHash.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-11-16 15:04:41 (GMT)
committerBrad King <brad.king@kitware.com>2011-11-16 15:15:44 (GMT)
commit293a7f4e2ae9b458d3efefcfe133d0ad5320a1b2 (patch)
treee3ff0fa7f5d7ba3d6722b0cc1eef4f917a95e7ea /Source/cmCryptoHash.cxx
parent46ab0561fc29446a736985816b005200aad9489c (diff)
downloadCMake-293a7f4e2ae9b458d3efefcfe133d0ad5320a1b2.zip
CMake-293a7f4e2ae9b458d3efefcfe133d0ad5320a1b2.tar.gz
CMake-293a7f4e2ae9b458d3efefcfe133d0ad5320a1b2.tar.bz2
cmCryptoHash: Provide factory "New" method
Construct a cmCryptoHash subclass instance based on the name of the desired hash algorithm.
Diffstat (limited to 'Source/cmCryptoHash.cxx')
-rw-r--r--Source/cmCryptoHash.cxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 411da58..a1505bd 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -15,6 +15,25 @@
#include "cm_sha2.h"
//----------------------------------------------------------------------------
+cmsys::auto_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo)
+{
+ if(strcmp(algo,"MD5") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashMD5); }
+ else if(strcmp(algo,"SHA1") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA1); }
+ else if(strcmp(algo,"SHA224") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA224); }
+ else if(strcmp(algo,"SHA256") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA256); }
+ else if(strcmp(algo,"SHA384") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA384); }
+ else if(strcmp(algo,"SHA512") == 0)
+ { return cmsys::auto_ptr<cmCryptoHash>(new cmCryptoHashSHA512); }
+ else
+ { return cmsys::auto_ptr<cmCryptoHash>(0); }
+}
+
+//----------------------------------------------------------------------------
std::string cmCryptoHash::HashString(const char* input)
{
this->Initialize();