diff Core/Toolbox.cpp @ 1833:47d032c48818

"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2015 12:22:44 +0100
parents 1065401501fb
children b1291df2f780
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Thu Nov 26 19:09:15 2015 +0100
+++ b/Core/Toolbox.cpp	Fri Nov 27 12:22:44 2015 +0100
@@ -494,16 +494,16 @@
 
   void Toolbox::ComputeMD5(std::string& result,
                            const void* data,
-                           size_t length)
+                           size_t size)
   {
     md5_state_s state;
     md5_init(&state);
 
-    if (length > 0)
+    if (size > 0)
     {
       md5_append(&state, 
                  reinterpret_cast<const md5_byte_t*>(data), 
-                 static_cast<int>(length));
+                 static_cast<int>(size));
     }
 
     md5_byte_t actualHash[16];
@@ -759,14 +759,16 @@
     return result;
   }
 
+
   void Toolbox::ComputeSHA1(std::string& result,
-                            const std::string& data)
+                            const void* data,
+                            size_t size)
   {
     boost::uuids::detail::sha1 sha1;
 
-    if (data.size() > 0)
+    if (size > 0)
     {
-      sha1.process_bytes(&data[0], data.size());
+      sha1.process_bytes(data, size);
     }
 
     unsigned int digest[5];
@@ -785,6 +787,20 @@
             digest[4]);
   }
 
+  void Toolbox::ComputeSHA1(std::string& result,
+                            const std::string& data)
+  {
+    if (data.size() > 0)
+    {
+      ComputeSHA1(result, data.c_str(), data.size());
+    }
+    else
+    {
+      ComputeSHA1(result, NULL, 0);
+    }
+  }
+
+
   bool Toolbox::IsSHA1(const char* str,
                        size_t size)
   {