浏览代码

stringapi: Accept strings when MD5 hashing data

Ben Boeckel 11 年之前
父节点
当前提交
77f60392d9
共有 4 个文件被更改,包括 11 次插入11 次删除
  1. 5 5
      Source/cmCryptoHash.cxx
  2. 2 2
      Source/cmCryptoHash.h
  3. 2 2
      Source/cmSystemTools.cxx
  4. 2 2
      Source/cmSystemTools.h

+ 5 - 5
Source/cmCryptoHash.cxx

@@ -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 "";

+ 2 - 2
Source/cmCryptoHash.h

@@ -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;

+ 2 - 2
Source/cmSystemTools.cxx

@@ -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;

+ 2 - 2
Source/cmSystemTools.h

@@ -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