changeset 809:8ce2f69436ca

do not return strings with base64
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 May 2014 16:39:53 +0200
parents 2d9a000aa3a6
children 401a9633e492
files Core/HttpServer/MongooseServer.cpp Core/Toolbox.cpp Core/Toolbox.h OrthancServer/ParsedDicomFile.cpp UnitTestsSources/FromDcmtk.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 6 files changed, 34 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp	Wed May 07 16:30:47 2014 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Wed May 07 16:39:53 2014 +0200
@@ -474,7 +474,8 @@
     }
 
     std::string b64 = s.substr(6);
-    std::string decoded = Toolbox::DecodeBase64(b64);
+    std::string decoded;
+    Toolbox::DecodeBase64(decoded, b64);
     size_t semicolons = decoded.find(':');
 
     if (semicolons == std::string::npos)
@@ -849,7 +850,9 @@
     Stop();
 
     std::string tag = std::string(username) + ":" + std::string(password);
-    registeredUsers_.insert(Toolbox::EncodeBase64(tag));
+    std::string encoded;
+    Toolbox::EncodeBase64(encoded, tag);
+    registeredUsers_.insert(encoded);
   }
 
   void MongooseServer::SetSslEnabled(bool enabled)
--- a/Core/Toolbox.cpp	Wed May 07 16:30:47 2014 +0200
+++ b/Core/Toolbox.cpp	Wed May 07 16:39:53 2014 +0200
@@ -491,14 +491,16 @@
   }
 
 
-  std::string Toolbox::EncodeBase64(const std::string& data)
+  void Toolbox::EncodeBase64(std::string& result, 
+                             const std::string& data)
   {
-    return base64_encode(data);
+    result = base64_encode(data);
   }
 
-  std::string Toolbox::DecodeBase64(const std::string& data)
+  void Toolbox::DecodeBase64(std::string& result, 
+                             const std::string& data)
   {
-    return base64_decode(data);
+    result = base64_decode(data);
   }
 
 
--- a/Core/Toolbox.h	Wed May 07 16:30:47 2014 +0200
+++ b/Core/Toolbox.h	Wed May 07 16:39:53 2014 +0200
@@ -95,9 +95,11 @@
 
     bool IsSHA1(const std::string& str);
 
-    std::string DecodeBase64(const std::string& data);
+    void DecodeBase64(std::string& result, 
+                      const std::string& data);
 
-    std::string EncodeBase64(const std::string& data);
+    void EncodeBase64(std::string& result, 
+                      const std::string& data);
 
     std::string GetPathToExecutable();
 
--- a/OrthancServer/ParsedDicomFile.cpp	Wed May 07 16:30:47 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed May 07 16:39:53 2014 +0200
@@ -1095,7 +1095,8 @@
     std::string mime, content;
     Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme);
 
-    std::string decoded = Toolbox::DecodeBase64(content);
+    std::string decoded;
+    Toolbox::DecodeBase64(decoded, content);
 
     if (mime == "image/png")
     {
--- a/UnitTestsSources/FromDcmtk.cpp	Wed May 07 16:30:47 2014 +0200
+++ b/UnitTestsSources/FromDcmtk.cpp	Wed May 07 16:39:53 2014 +0200
@@ -65,7 +65,8 @@
   ASSERT_EQ("image/png", m);
   ASSERT_EQ(116, c.size());
 
-  std::string cc = Toolbox::DecodeBase64(c);
+  std::string cc;
+  Toolbox::DecodeBase64(cc, c);
   PngReader reader;
   reader.ReadFromMemory(cc);
 
--- a/UnitTestsSources/UnitTestsMain.cpp	Wed May 07 16:30:47 2014 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Wed May 07 16:39:53 2014 +0200
@@ -306,14 +306,25 @@
 }
 
 
+static std::string EncodeBase64Bis(const std::string& s)
+{
+  std::string result;
+  Toolbox::EncodeBase64(result, s);
+  return result;
+}
+
+
 TEST(Toolbox, Base64)
 {
-  ASSERT_EQ("", Toolbox::EncodeBase64(""));
-  ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a"));
+  ASSERT_EQ("", EncodeBase64Bis(""));
+  ASSERT_EQ("YQ==", EncodeBase64Bis("a"));
 
   const std::string hello = "SGVsbG8gd29ybGQ=";
-  ASSERT_EQ(hello, Toolbox::EncodeBase64("Hello world"));
-  ASSERT_EQ("Hello world", Toolbox::DecodeBase64(hello));
+  ASSERT_EQ(hello, EncodeBase64Bis("Hello world"));
+
+  std::string decoded;
+  Toolbox::DecodeBase64(decoded, hello);
+  ASSERT_EQ("Hello world", decoded);
 }
 
 TEST(Toolbox, PathToExecutable)