From bc51caac323524b8502dbdc513b4512844ba1acf Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 17 May 2023 14:26:05 +0200
Subject: [PATCH] ENH: remove sign from SHA1Digest cdata_bytes(), data_bytes()

- this refinement of commit 81807646ca7c makes these methods
  consistent with other objects/containers.

  The 'unsigned char' access is still available via cdata()
---
 .../test/parallel-comm2/Test-parallel-comm2.C     |  4 ++--
 src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C     |  4 +---
 src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H  | 15 +++++++++------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/applications/test/parallel-comm2/Test-parallel-comm2.C b/applications/test/parallel-comm2/Test-parallel-comm2.C
index 660bc6fb943..7ccd11cf29b 100644
--- a/applications/test/parallel-comm2/Test-parallel-comm2.C
+++ b/applications/test/parallel-comm2/Test-parallel-comm2.C
@@ -261,11 +261,11 @@ int main(int argc, char *argv[])
         }
 
         {
-            const SHA1Digest myHostDigest(SHA1(hostName()).digest());
+            const SHA1Digest myDigest(SHA1(hostName()).digest());
 
             UPstream::mpiGather
             (
-                reinterpret_cast<const char*>(myHostDigest.cdata_bytes()),
+                myDigest.cdata_bytes(),     // Send
                 SHA1Digest::max_size(),     // Num send per proc
                 digests.data_bytes(),       // Recv
                 SHA1Digest::max_size(),     // Num recv per proc
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
index 3d6dc38439b..ac967f1a1e8 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
@@ -88,11 +88,9 @@ static List<int> getHostGroupIds(const label parentCommunicator)
     SHA1Digest myDigest(SHA1(hostName()).digest());
 
     // The fixed-length digest allows use of MPI_Gather
-    // and avoids Pstream::gatherList() during setup...
-
     UPstream::mpiGather
     (
-        reinterpret_cast<const char*>(myDigest.cdata_bytes()),
+        myDigest.cdata_bytes(),     // Send
         SHA1Digest::max_size(),     // Num send per proc
         digests.data_bytes(),       // Recv
         SHA1Digest::max_size(),     // Num recv per proc
diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
index f3b3535f5b8..77a065e11fc 100644
--- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
+++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
@@ -128,16 +128,19 @@ public:
         //- Raw digest data (20 bytes) - const access
         const unsigned char* cdata() const noexcept { return dig_.data(); }
 
-        //- Raw digest data (20 bytes) - const access
-        const unsigned char* cdata_bytes() const noexcept
+        //- Raw digest char data (20 bytes) - const access.
+        //- For consistency with other objects, these are \em not unsigned.
+        const char* cdata_bytes() const noexcept
         {
-            return dig_.data();
+            return reinterpret_cast<const char*>(dig_.data());
         }
 
-        //- Raw digest data (20 bytes) - non-const access. Use with caution!
-        unsigned char* data_bytes() noexcept
+        //- Raw digest char data (20 bytes) - non-const access.
+        //- For consistency with other objects, these are \em not unsigned.
+        //- Use with caution - generally for broadcasting only.
+        char* data_bytes() noexcept
         {
-            return dig_.data();
+            return reinterpret_cast<char*>(dig_.data());
         }
 
         //- The number of bytes in digest (20)
-- 
GitLab