diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStringCommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmStringCommand.h | 5 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index d239c063ad..f2f2681518 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) { diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 52b83d9f37..452f4a1bde 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -76,6 +76,8 @@ public: " string(REPLACE <match_string>\n" " <replace_string> <output variable>\n" " <input> [<input>...])\n" + " string(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512>\n" + " <output variable> <input>)\n" " string(COMPARE EQUAL <string1> <string2> <output variable>)\n" " string(COMPARE NOTEQUAL <string1> <string2> <output variable>)\n" " string(COMPARE LESS <string1> <string2> <output variable>)\n" @@ -103,6 +105,8 @@ public: "backslash through argument parsing.\n" "REPLACE will replace all occurrences of match_string in the input with " "replace_string and store the result in the output.\n" + "MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 " + "will compute a cryptographic hash of the input string.\n" "COMPARE EQUAL/NOTEQUAL/LESS/GREATER will compare the strings and " "store true or false in the output variable.\n" "ASCII will convert all numbers into corresponding ASCII characters.\n" @@ -150,6 +154,7 @@ protected: bool RegexMatch(std::vector<std::string> const& args); bool RegexMatchAll(std::vector<std::string> const& args); bool RegexReplace(std::vector<std::string> const& args); + bool HandleHashCommand(std::vector<std::string> const& args); bool HandleToUpperLowerCommand(std::vector<std::string> const& args, bool toUpper); bool HandleCompareCommand(std::vector<std::string> const& args); |