[Cmake-commits] CMake branch, next, updated. v3.6.1-1221-gb2d8050

Brad King brad.king at kitware.com
Wed Aug 10 11:52:01 EDT 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  b2d8050a9bc4ade6a4ca5b41af91c61cb1bd33ab (commit)
       via  48137ebcf2e3a03e804223bbbb409421a424a9ea (commit)
       via  0529ab5c59664c55c70f3e294374161e93fb1e4f (commit)
       via  36f230df30f4308a6b8db51aad38cbd0028ebdc8 (commit)
       via  14b4657dcceb1a7025e895fb55a61c14e62b6d1e (commit)
       via  57090700171551a723a1a25628b6bf806a358d02 (commit)
      from  1c9b455c48aed37ef0992f40fd4cf189e648c45f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b2d8050a9bc4ade6a4ca5b41af91c61cb1bd33ab
commit b2d8050a9bc4ade6a4ca5b41af91c61cb1bd33ab
Merge: 1c9b455 48137eb
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Wed Aug 10 11:52:00 2016 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Aug 10 11:52:00 2016 -0400

    Merge topic 'autogen-same-name' into next
    
    48137ebc cmFilePathUuid: Use Binary interface of cmCryptoHash
    0529ab5c cmCryptoHash: New ByteHash methods that return a byte vector
    36f230df cmCryptoHash: Return byte vector from internal Finalize method
    14b4657d cmCryptoHash: New byte hash to string function
    57090700 cmCryptoHash: Documentation comments


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=48137ebcf2e3a03e804223bbbb409421a424a9ea
commit 48137ebcf2e3a03e804223bbbb409421a424a9ea
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 11:59:05 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 11:51:49 2016 -0400

    cmFilePathUuid: Use Binary interface of cmCryptoHash

diff --git a/Source/cmFilePathUuid.cxx b/Source/cmFilePathUuid.cxx
index 592c3a6..2839b63 100644
--- a/Source/cmFilePathUuid.cxx
+++ b/Source/cmFilePathUuid.cxx
@@ -111,46 +111,22 @@ std::string cmFilePathUuid::GetChecksumString(
   const std::string& sourceFilename, const std::string& sourceRelPath,
   const std::string& sourceRelSeed)
 {
-  // Calculate the file ( seed + relative path + name ) checksum
   std::string checksumBase64;
-
-  std::vector<unsigned char> hashBytes;
-  {
-    // Acquire hash in a hex value string
-    std::string hexHash = cmCryptoHash::New("SHA256")->HashString(
-      (sourceRelSeed + sourceRelPath + sourceFilename).c_str());
-    // Convert hex value string to bytes
-    hashBytes.resize(hexHash.size() / 2);
-    for (unsigned int ii = 0; ii != hashBytes.size(); ++ii) {
-      unsigned char hbyte[2] = { 0, 0 };
-      for (unsigned int jj = 0; jj != 2; ++jj) {
-        const unsigned char nibble = hexHash[ii * 2 + jj];
-        if ('0' <= nibble && nibble <= '9') {
-          hbyte[jj] = static_cast<unsigned char>(nibble - '0');
-        } else if ('a' <= nibble && nibble <= 'f') {
-          hbyte[jj] = static_cast<unsigned char>(nibble - 'a' + 10);
-        } else if ('A' <= nibble && nibble <= 'f') {
-          hbyte[jj] = static_cast<unsigned char>(nibble - 'A' + 10);
-        } else {
-          // Unexpected non hex character
-          std::cerr << "Unexpected non hex character in checksum string";
-          exit(-1);
-        }
-      }
-      hashBytes[ii] = static_cast<unsigned char>(hbyte[1] | (hbyte[0] << 4));
-    }
-  }
-  // Convert hash bytes to Base64 text string
   {
+    // Calculate the file ( seed + relative path + name ) checksum
+    std::vector<unsigned char> hashBytes =
+      cmCryptoHash::New("SHA256")->ByteHashString(
+        (sourceRelSeed + sourceRelPath + sourceFilename).c_str());
+    // Convert hash bytes to Base64 text string
     std::vector<unsigned char> base64Bytes(hashBytes.size() * 2, 0);
     cmsysBase64_Encode(&hashBytes[0], hashBytes.size(), &base64Bytes[0], 0);
     checksumBase64 = reinterpret_cast<const char*>(&base64Bytes[0]);
-    // Base64 allows '+' and '/' characters.
-    // Both are problematic when used in file names.
-    // Replace them with safer alternatives.
-    std::replace(checksumBase64.begin(), checksumBase64.end(), '+', '_');
-    std::replace(checksumBase64.begin(), checksumBase64.end(), '/', '-');
   }
+  // Base64 allows '/', '+' and '=' characters which are problematic
+  // when used in file names. Replace them with safer alternatives.
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '/', '-');
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '+', '_');
+  std::replace(checksumBase64.begin(), checksumBase64.end(), '=', '_');
 
   return checksumBase64;
 }

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0529ab5c59664c55c70f3e294374161e93fb1e4f
commit 0529ab5c59664c55c70f3e294374161e93fb1e4f
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 11:30:06 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 11:51:49 2016 -0400

    cmCryptoHash: New ByteHash methods that return a byte vector

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index dafe7c6..ec885d8 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -65,43 +65,57 @@ std::string cmCryptoHash::ByteHashToString(
   return res;
 }
 
-std::string cmCryptoHash::HashString(const std::string& input)
+std::vector<unsigned char> cmCryptoHash::ByteHashString(
+  const std::string& input)
 {
   this->Initialize();
   this->Append(reinterpret_cast<unsigned char const*>(input.c_str()),
                static_cast<int>(input.size()));
-  return ByteHashToString(this->Finalize());
+  return this->Finalize();
 }
 
-std::string cmCryptoHash::HashFile(const std::string& file)
+std::vector<unsigned char> cmCryptoHash::ByteHashFile(const std::string& file)
 {
   cmsys::ifstream fin(file.c_str(), std::ios::in | std::ios::binary);
-  if (!fin) {
-    return "";
+  if (fin) {
+    this->Initialize();
+    {
+      // Should be efficient enough on most system:
+      cm_sha2_uint64_t buffer[512];
+      char* buffer_c = reinterpret_cast<char*>(buffer);
+      unsigned char const* buffer_uc =
+        reinterpret_cast<unsigned char const*>(buffer);
+      // This copy loop is very sensitive on certain platforms with
+      // slightly broken stream libraries (like HPUX).  Normally, it is
+      // incorrect to not check the error condition on the fin.read()
+      // before using the data, but the fin.gcount() will be zero if an
+      // error occurred.  Therefore, the loop should be safe everywhere.
+      while (fin) {
+        fin.read(buffer_c, sizeof(buffer));
+        if (int gcount = static_cast<int>(fin.gcount())) {
+          this->Append(buffer_uc, gcount);
+        }
+      }
+    }
+    if (fin.eof()) {
+      // Success
+      return this->Finalize();
+    }
+    // Finalize anyway
+    this->Finalize();
   }
+  // Return without success
+  return std::vector<unsigned char>();
+}
 
-  this->Initialize();
+std::string cmCryptoHash::HashString(const std::string& input)
+{
+  return ByteHashToString(this->ByteHashString(input));
+}
 
-  // Should be efficient enough on most system:
-  cm_sha2_uint64_t buffer[512];
-  char* buffer_c = reinterpret_cast<char*>(buffer);
-  unsigned char const* buffer_uc =
-    reinterpret_cast<unsigned char const*>(buffer);
-  // This copy loop is very sensitive on certain platforms with
-  // slightly broken stream libraries (like HPUX).  Normally, it is
-  // incorrect to not check the error condition on the fin.read()
-  // before using the data, but the fin.gcount() will be zero if an
-  // error occurred.  Therefore, the loop should be safe everywhere.
-  while (fin) {
-    fin.read(buffer_c, sizeof(buffer));
-    if (int gcount = static_cast<int>(fin.gcount())) {
-      this->Append(buffer_uc, gcount);
-    }
-  }
-  if (fin.eof()) {
-    return ByteHashToString(this->Finalize());
-  }
-  return "";
+std::string cmCryptoHash::HashFile(const std::string& file)
+{
+  return ByteHashToString(this->ByteHashFile(file));
 }
 
 cmCryptoHashMD5::cmCryptoHashMD5()
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index ab50e82..4e92b06 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -23,22 +23,37 @@ class cmCryptoHash
 {
 public:
   virtual ~cmCryptoHash() {}
+
   /// @brief Returns a new hash generator of the requested type
   /// @arg algo Hash type name. Supported hash types are
   ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512
   /// @return A valid auto pointer if algo is supported or
   ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+
   /// @brief Converts a hex character to its binary value (4 bits)
   /// @arg input Hex character [0-9a-fA-F].
   /// @arg output Binary value of the input character (4 bits)
   /// @return True if input was a valid hex character
   static bool IntFromHexDigit(char input, char& output);
+
   /// @brief Converts a byte hash to a sequence of hex character pairs
   static std::string ByteHashToString(const std::vector<unsigned char>& hash);
+
+  /// @brief Calculates a binary hash from string input data
+  /// @return Binary hash vector
+  std::vector<unsigned char> ByteHashString(const std::string& input);
+
+  /// @brief Calculates a binary hash from file content
+  /// @see ByteHashString()
+  /// @return Non empty binary hash vector if the file was read successfully.
+  ///         An empty vector otherwise.
+  std::vector<unsigned char> ByteHashFile(const std::string& file);
+
   /// @brief Calculates a hash string from string input data
   /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);
+
   /// @brief Calculates a hash string from file content
   /// @see HashString()
   /// @return Non empty hash string if the file was read successfully.

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=36f230df30f4308a6b8db51aad38cbd0028ebdc8
commit 36f230df30f4308a6b8db51aad38cbd0028ebdc8
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 11:08:15 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 11:51:40 2016 -0400

    cmCryptoHash: Return byte vector from internal Finalize method
    
    Some callers may want the raw byte vector instead of the hex character
    string.  Convert the internal implementation to use this so that we
    can later add public APIs to get it.

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 59b9abd..dafe7c6 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -70,7 +70,7 @@ std::string cmCryptoHash::HashString(const std::string& input)
   this->Initialize();
   this->Append(reinterpret_cast<unsigned char const*>(input.c_str()),
                static_cast<int>(input.size()));
-  return this->Finalize();
+  return ByteHashToString(this->Finalize());
 }
 
 std::string cmCryptoHash::HashFile(const std::string& file)
@@ -99,7 +99,7 @@ std::string cmCryptoHash::HashFile(const std::string& file)
     }
   }
   if (fin.eof()) {
-    return this->Finalize();
+    return ByteHashToString(this->Finalize());
   }
   return "";
 }
@@ -124,11 +124,11 @@ void cmCryptoHashMD5::Append(unsigned char const* buf, int sz)
   cmsysMD5_Append(this->MD5, buf, sz);
 }
 
-std::string cmCryptoHashMD5::Finalize()
+std::vector<unsigned char> cmCryptoHashMD5::Finalize()
 {
-  char md5out[32];
-  cmsysMD5_FinalizeHex(this->MD5, md5out);
-  return std::string(md5out, 32);
+  std::vector<unsigned char> hash(16, 0);
+  cmsysMD5_Finalize(this->MD5, &hash[0]);
+  return hash;
 }
 
 #define cmCryptoHash_SHA_CLASS_IMPL(SHA)                                      \
@@ -142,11 +142,11 @@ std::string cmCryptoHashMD5::Finalize()
   {                                                                           \
     SHA##_Update(this->SHA, buf, sz);                                         \
   }                                                                           \
-  std::string cmCryptoHash##SHA::Finalize()                                   \
+  std::vector<unsigned char> cmCryptoHash##SHA::Finalize()                    \
   {                                                                           \
-    char out[SHA##_DIGEST_STRING_LENGTH];                                     \
-    SHA##_End(this->SHA, out);                                                \
-    return std::string(out, SHA##_DIGEST_STRING_LENGTH - 1);                  \
+    std::vector<unsigned char> hash(SHA##_DIGEST_STRING_LENGTH, 0);           \
+    SHA##_Final(&hash[0], this->SHA);                                         \
+    return hash;                                                              \
   }
 
 cmCryptoHash_SHA_CLASS_IMPL(SHA1) cmCryptoHash_SHA_CLASS_IMPL(SHA224)
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 80ab269..ab50e82 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -48,7 +48,7 @@ public:
 protected:
   virtual void Initialize() = 0;
   virtual void Append(unsigned char const*, int) = 0;
-  virtual std::string Finalize() = 0;
+  virtual std::vector<unsigned char> Finalize() = 0;
 };
 
 class cmCryptoHashMD5 : public cmCryptoHash
@@ -62,7 +62,7 @@ public:
 protected:
   void Initialize() CM_OVERRIDE;
   void Append(unsigned char const* buf, int sz) CM_OVERRIDE;
-  std::string Finalize() CM_OVERRIDE;
+  std::vector<unsigned char> Finalize() CM_OVERRIDE;
 };
 
 #define cmCryptoHash_SHA_CLASS_DECL(SHA)                                      \
@@ -77,7 +77,7 @@ protected:
   protected:                                                                  \
     virtual void Initialize();                                                \
     virtual void Append(unsigned char const* buf, int sz);                    \
-    virtual std::string Finalize();                                           \
+    virtual std::vector<unsigned char> Finalize();                            \
   }
 
 cmCryptoHash_SHA_CLASS_DECL(SHA1);

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=14b4657dcceb1a7025e895fb55a61c14e62b6d1e
commit 14b4657dcceb1a7025e895fb55a61c14e62b6d1e
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 10:35:19 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 11:46:33 2016 -0400

    cmCryptoHash: New byte hash to string function

diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 8d60c1f..59b9abd 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -34,6 +34,37 @@ CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
   }
 }
 
+bool cmCryptoHash::IntFromHexDigit(char input, char& output)
+{
+  if (input >= '0' && input <= '9') {
+    output = char(input - '0');
+    return true;
+  } else if (input >= 'a' && input <= 'f') {
+    output = char(input - 'a' + 0xA);
+    return true;
+  } else if (input >= 'A' && input <= 'F') {
+    output = char(input - 'A' + 0xA);
+    return true;
+  }
+  return false;
+}
+
+std::string cmCryptoHash::ByteHashToString(
+  const std::vector<unsigned char>& hash)
+{
+  // Map from 4-bit index to hexadecimal representation.
+  static char const hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+                                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+
+  std::string res;
+  for (std::vector<unsigned char>::const_iterator vit = hash.begin();
+       vit != hash.end(); ++vit) {
+    res.push_back(hex[(*vit) >> 4]);
+    res.push_back(hex[(*vit) & 0xF]);
+  }
+  return res;
+}
+
 std::string cmCryptoHash::HashString(const std::string& input)
 {
   this->Initialize();
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 84dea9b..80ab269 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -29,6 +29,13 @@ public:
   /// @return A valid auto pointer if algo is supported or
   ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+  /// @brief Converts a hex character to its binary value (4 bits)
+  /// @arg input Hex character [0-9a-fA-F].
+  /// @arg output Binary value of the input character (4 bits)
+  /// @return True if input was a valid hex character
+  static bool IntFromHexDigit(char input, char& output);
+  /// @brief Converts a byte hash to a sequence of hex character pairs
+  static std::string ByteHashToString(const std::vector<unsigned char>& hash);
   /// @brief Calculates a hash string from string input data
   /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);

https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=57090700171551a723a1a25628b6bf806a358d02
commit 57090700171551a723a1a25628b6bf806a358d02
Author:     Sebastian Holtermann <sebholt at xwmw.org>
AuthorDate: Wed Aug 10 09:54:49 2016 +0200
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Wed Aug 10 11:46:33 2016 -0400

    cmCryptoHash: Documentation comments

diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index 6aaaf93..84dea9b 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -16,12 +16,26 @@
 
 #include <cm_auto_ptr.hxx>
 
+/**
+ * @brief Abstract base class for cryptographic hash generators
+ */
 class cmCryptoHash
 {
 public:
   virtual ~cmCryptoHash() {}
+  /// @brief Returns a new hash generator of the requested type
+  /// @arg algo Hash type name. Supported hash types are
+  ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512
+  /// @return A valid auto pointer if algo is supported or
+  ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+  /// @brief Calculates a hash string from string input data
+  /// @return Sequence of hex characters pairs for each byte of the binary hash
   std::string HashString(const std::string& input);
+  /// @brief Calculates a hash string from file content
+  /// @see HashString()
+  /// @return Non empty hash string if the file was read successfully.
+  ///         An empty string otherwise.
   std::string HashFile(const std::string& file);
 
 protected:

-----------------------------------------------------------------------

Summary of changes:
 Source/cmCryptoHash.cxx   |  111 +++++++++++++++++++++++++++++++--------------
 Source/cmCryptoHash.h     |   42 +++++++++++++++--
 Source/cmFilePathUuid.cxx |   44 ++++--------------
 3 files changed, 127 insertions(+), 70 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list