diff Plugins/Engine/OrthancPlugins.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 31df3b48925e
children 859224214616
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Thu Nov 26 19:09:15 2015 +0100
+++ b/Plugins/Engine/OrthancPlugins.cpp	Fri Nov 27 12:22:44 2015 +0100
@@ -1495,6 +1495,31 @@
   }
 
 
+  void OrthancPlugins::ComputeHash(_OrthancPluginService service,
+                                   const void* parameters)
+  {
+    const _OrthancPluginComputeHash& p =
+      *reinterpret_cast<const _OrthancPluginComputeHash*>(parameters);
+ 
+    std::string hash;
+    switch (service)
+    {
+      case _OrthancPluginService_ComputeMd5:
+        Toolbox::ComputeMD5(hash, p.buffer, p.size);
+        break;
+
+      case _OrthancPluginService_ComputeSha1:
+        Toolbox::ComputeSHA1(hash, p.buffer, p.size);
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+   
+    *p.result = CopyString(hash);
+  }
+
+
   void OrthancPlugins::ApplyCreateImage(_OrthancPluginService service,
                                         const void* parameters)
   {
@@ -2100,6 +2125,11 @@
         ApplyCreateImage(service, parameters);
         return true;
 
+      case _OrthancPluginService_ComputeMd5:
+      case _OrthancPluginService_ComputeSha1:
+        ComputeHash(service, parameters);
+        return true;
+
       default:
       {
         // This service is unknown to the Orthanc plugin engine