Move SecureString class to ipmid/types.hpp

SecureString class doesn't have access in user_library to use in
other files

Tested:
Added class to ipmid/types.hpp from user_channel/user_mgmt.hpp
Build got successful.

Signed-off-by: Snehalatha Venkatesh <snehalathax.v@intel.com>
Change-Id: I5e0c4bb0744113e70540b272f16a5116421048fb
diff --git a/include/ipmid/types.hpp b/include/ipmid/types.hpp
index 0e15e85..6eec66b 100644
--- a/include/ipmid/types.hpp
+++ b/include/ipmid/types.hpp
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <openssl/crypto.h>
 #include <stdint.h>
 
 #include <map>
@@ -237,4 +238,32 @@
 
 } // namespace network
 
+template <typename T>
+class SecureAllocator : public std::allocator<T>
+{
+  public:
+    template <typename U>
+    struct rebind
+    {
+        typedef SecureAllocator<U> other;
+    };
+
+    void deallocate(T* p, size_t n)
+    {
+        OPENSSL_cleanse(p, n);
+        return std::allocator<T>::deallocate(p, n);
+    }
+};
+using SecureString =
+    std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
+
 } // namespace ipmi
+namespace std
+{
+
+template <>
+inline ipmi::SecureString::~SecureString()
+{
+    OPENSSL_cleanse(&((*this)[0]), this->size());
+}
+} // namespace std
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp
index 036f73d..6b31eb9 100644
--- a/user_channel/user_mgmt.cpp
+++ b/user_channel/user_mgmt.cpp
@@ -27,6 +27,7 @@
 #include <boost/interprocess/sync/scoped_lock.hpp>
 #include <cerrno>
 #include <fstream>
+#include <ipmid/types.hpp>
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
diff --git a/user_channel/user_mgmt.hpp b/user_channel/user_mgmt.hpp
index d41a387..6dbda25 100644
--- a/user_channel/user_mgmt.hpp
+++ b/user_channel/user_mgmt.hpp
@@ -402,44 +402,4 @@
     void cacheUserDataFile();
 };
 
-template <typename T>
-class SecureAllocator : public std::allocator<T>
-{
-  public:
-    typedef size_t size_type;
-    typedef T* pointer;
-    typedef const T* const_pointer;
-
-    template <typename _Tp1>
-    struct rebind
-    {
-        typedef SecureAllocator<_Tp1> other;
-    };
-    pointer allocate(size_type n, const void* hint = 0)
-    {
-        return std::allocator<T>::allocate(n, hint);
-    }
-
-    void deallocate(pointer p, size_type n)
-    {
-        OPENSSL_cleanse(p, n);
-        return std::allocator<T>::deallocate(p, n);
-    }
-
-    SecureAllocator() throw() : std::allocator<T>()
-    {
-    }
-    SecureAllocator(const SecureAllocator& a) throw() : std::allocator<T>(a)
-    {
-    }
-    template <class U>
-    SecureAllocator(const SecureAllocator<U>& a) throw() : std::allocator<T>(a)
-    {
-    }
-    ~SecureAllocator() throw()
-    {
-    }
-};
-using SecureString = std::basic_string<char, std::char_traits<char>,
-                                       ipmi::SecureAllocator<char>>;
 } // namespace ipmi