diff options
author | Brad King <brad.king@kitware.com> | 2011-11-16 15:12:18 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-11-16 15:29:35 (GMT) |
commit | 2e9c26cf9616fead92ec65eefc696bcf9761b996 (patch) | |
tree | 35460a3ee2bde7485174fe3adefa4fca19e0ac68 /Source/cmStringCommand.cxx | |
parent | 293a7f4e2ae9b458d3efefcfe133d0ad5320a1b2 (diff) | |
download | CMake-2e9c26cf9616fead92ec65eefc696bcf9761b996.zip CMake-2e9c26cf9616fead92ec65eefc696bcf9761b996.tar.gz CMake-2e9c26cf9616fead92ec65eefc696bcf9761b996.tar.bz2 |
Add string(MD5) and string(SHA*) commands to compute hashes
Provide a CMake-language binding to these cryptographic hashes. Add a
string() command API for MD5, SHA1, SHA224, SHA256, SHA384, and SHA512.
Diffstat (limited to 'Source/cmStringCommand.cxx')
-rw-r--r-- | Source/cmStringCommand.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index d239c06..f2f2681 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -10,6 +10,8 @@ See the License for more information. ============================================================================*/ #include "cmStringCommand.h" +#include "cmCryptoHash.h" + #include <cmsys/RegularExpression.hxx> #include <cmsys/SystemTools.hxx> @@ -36,6 +38,15 @@ bool cmStringCommand { return this->HandleReplaceCommand(args); } + else if ( subCommand == "MD5" || + subCommand == "SHA1" || + subCommand == "SHA224" || + subCommand == "SHA256" || + subCommand == "SHA384" || + subCommand == "SHA512" ) + { + return this->HandleHashCommand(args); + } else if(subCommand == "TOLOWER") { return this->HandleToUpperLowerCommand(args, false); @@ -83,6 +94,27 @@ bool cmStringCommand } //---------------------------------------------------------------------------- +bool cmStringCommand::HandleHashCommand(std::vector<std::string> const& args) +{ + if(args.size() != 3) + { + cmOStringStream e; + e << args[0] << " requires an output variable and an input string"; + this->SetError(e.str().c_str()); + return false; + } + + cmsys::auto_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str())); + if(hash.get()) + { + std::string out = hash->HashString(args[2].c_str()); + this->Makefile->AddDefinition(args[1].c_str(), out.c_str()); + return true; + } + return false; +} + +//---------------------------------------------------------------------------- bool cmStringCommand::HandleToUpperLowerCommand( std::vector<std::string> const& args, bool toUpper) { |