Minor re-factoring: boost::vector replaced with std::vector.
authorMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Thu, 23 Oct 2014 08:00:29 +0000 (10:00 +0200)
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Tue, 17 Feb 2015 10:09:41 +0000 (11:09 +0100)
<vector> header cleanup.

Change-Id: I8408a4943f22e5fb18a08c40e9e0b5f9c938b34c

12 files changed:
src/include/ckm/ckm-certificate.h
src/include/ckm/ckm-control.h
src/include/ckm/ckm-manager.h
src/include/ckm/ckm-password.h
src/include/ckm/ckm-pkcs12.h
src/include/ckm/ckm-raw-buffer.h
src/manager/client/client-common.h
src/manager/common/message-buffer.h
src/manager/common/pkcs12-impl.h
src/manager/common/protocols.cpp
src/manager/common/protocols.h
src/manager/service/file-system.cpp

index b19f1ed..f76b979 100644 (file)
@@ -21,6 +21,7 @@
  */
 #pragma once
 
+#include <vector>
 #include <memory>
 
 #include <ckm/ckm-type.h>
index 1f6954b..723a8d4 100644 (file)
@@ -22,7 +22,6 @@
 #pragma once
 
 #include <string>
-#include <vector>
 #include <memory>
 
 #include <ckm/ckm-error.h>
index a466cfb..d995f5f 100644 (file)
@@ -22,7 +22,6 @@
 #pragma once
 
 #include <string>
-#include <vector>
 #include <memory>
 
 #include <ckm/ckm-certificate.h>
index b12e218..efd891a 100644 (file)
  *  limitations under the License
  *
  *
- * @file        safe-buffer.h
+ * @file        ckm-password.h
  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
  * @version     1.0
- * @brief       Custom allocator for std
+ * @brief       Password holder with auto-erase on cleanup
  */
 
 #ifndef _SAFE_PASSWORD_H_
 #define _SAFE_PASSWORD_H_
 
 #include <ckm/ckm-raw-buffer.h>
-#include <boost/container/string.hpp>
+#include <string>
 
 namespace CKM {
 
-typedef boost::container::basic_string<char, std::char_traits<char>, erase_on_dealloc<char>> Password;
+typedef std::basic_string<char, std::char_traits<char>, std_erase_on_dealloc<char>> Password;
 
 } // namespace CKM
 
-#endif //_ERASE_ON_DEALLOC_H_
+#endif //_SAFE_PASSWORD_H_
index cdb4613..4c2d5b7 100644 (file)
@@ -21,7 +21,6 @@
  */
 #pragma once
 
-#include <vector>
 #include <memory>
 
 #include <ckm/ckm-certificate.h>
index 75335c8..02c9d6b 100644 (file)
@@ -13,7 +13,7 @@
  *  limitations under the License
  *
  *
- * @file        safe-buffer.h
+ * @file        ckm-raw-buffer.h
  * @author      Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
  * @version     1.0
  * @brief       Custom allocator for std
 #ifndef _SAFE_BUFFER_H_
 #define _SAFE_BUFFER_H_
 
-#include <boost/container/vector.hpp>
+#include <stddef.h>
+#include <string.h>
+#include <vector>
 
 namespace CKM {
 
 template <typename T>
-struct erase_on_dealloc {
-    typedef T value_type;
+struct std_erase_on_dealloc
+{
+    // MJK: if re-factoring, remember not to inherit from the std::allocator !
+    // MJK: to be replaced with much shorter version once std::allocator_traits
+    // becomes supported in STL containers (i.e. list, vector and string)
+    typedef size_t    size_type;
+    typedef ptrdiff_t difference_type;
+    typedef T*        pointer;
+    typedef const T*  const_pointer;
+    typedef T&        reference;
+    typedef const T&  const_reference;
+    typedef T         value_type;
 
-    erase_on_dealloc() noexcept {}
+    std_erase_on_dealloc() = default;
 
     template <typename U>
-    erase_on_dealloc (const erase_on_dealloc<U>&) noexcept {}
+    std_erase_on_dealloc(const std_erase_on_dealloc<U>&) {}
 
-    T* allocate (std::size_t n)
-    {
+    T* allocate(std::size_t n) {
         return static_cast<T*>(::operator new(n*sizeof(T)));
     }
 
-    void deallocate (T* p, std::size_t n)
-    {
+    void deallocate(T* ptr, std::size_t n) {
         // clear the memory before deleting
-        memset(p,0,n*sizeof(T));
-        ::operator delete(p);
+        memset(ptr, 0 ,n * sizeof(T));
+        ::operator delete(ptr);
+    }
+
+    template<typename _Tp1>
+    struct rebind
+    {
+        typedef std_erase_on_dealloc<_Tp1> other;
+    };
+
+    void construct(pointer p, const T& val) {
+        new (p) T(val);
+    }
+
+    void destroy(pointer p) {
+        p->~T();
+    }
+
+    size_type max_size() const {
+        return size_type(-1);
     }
 };
 
 template <typename T, typename U>
-constexpr bool operator== (const erase_on_dealloc<T>&, const erase_on_dealloc<U>&) noexcept
-{
+inline bool operator == (const std_erase_on_dealloc<T>&, const std_erase_on_dealloc<U>&) {
     return true;
 }
 
 template <typename T, typename U>
-constexpr bool operator!= (const erase_on_dealloc<T>&, const erase_on_dealloc<U>&) noexcept
-{
-    return false;
+inline bool operator != (const std_erase_on_dealloc<T>& a, const std_erase_on_dealloc<U>& b) {
+    return !(a == b);
 }
 
+
 /*
  * TODO replace with:
  *
@@ -68,12 +95,11 @@ constexpr bool operator!= (const erase_on_dealloc<T>&, const erase_on_dealloc<U>
  *
  *  typedef SafeBuffer<unsigned char> RawBuffer
  *
- * when gcc 4.7/4.8 is available. Also replace boost::vector with std::vector
- * in other parts of code
+ * when gcc 4.7/4.8 is available.
  */
 template <typename T>
 struct SafeBuffer {
-    typedef boost::container::vector<T, erase_on_dealloc<T>> Type;
+    typedef std::vector<T, std_erase_on_dealloc<T>> Type;
 };
 
 // used to pass password and raw key data
@@ -81,4 +107,4 @@ typedef SafeBuffer<unsigned char>::Type RawBuffer;
 
 } // namespace CKM
 
-#endif //_ERASE_ON_DEALLOC_H_
+#endif //_SAFE_BUFFER_H_
index 471e3e5..06cddf7 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef _KEY_MANAGER_CLIENT_
 #define _KEY_MANAGER_CLIENT_
 
+#include <unistd.h>
+
 #include <vector>
 #include <functional>
 
index bf5d5e0..4112f43 100644 (file)
@@ -26,8 +26,6 @@
 #ifndef _CENT_KEY_MNG_SOCKET_BUFFER_
 #define _CENT_KEY_MNG_SOCKET_BUFFER_
 
-#include <vector>
-
 #include <dpl/binary_queue.h>
 #include <dpl/exception.h>
 #include <dpl/serialization.h>
index 3ec8fc3..b1d1c8f 100644 (file)
@@ -21,7 +21,6 @@
 #pragma once
 
 #include <memory>
-#include <vector>
 
 #include <ckm/ckm-pkcs12.h>
 
index 7c77a68..c4df066 100644 (file)
@@ -74,23 +74,5 @@ const char* toDBAccessRight(AccessRight access_right_type) {
     }
 }
 
-PolicySerializable::PolicySerializable()
-{}
-
-
-PolicySerializable::PolicySerializable(const Policy &policy)
-  : Policy(policy)
-{}
-
-PolicySerializable::PolicySerializable(IStream &stream) {
-    Deserialization::Deserialize(stream, password);
-    Deserialization::Deserialize(stream, extractable);
-}
-
-void PolicySerializable::Serialize(IStream &stream) const {
-    Serialization::Serialize(stream, password);
-    Serialization::Serialize(stream, extractable);
-}
-
 } // namespace CKM
 
index 1297b01..594d0e1 100644 (file)
@@ -92,10 +92,16 @@ const char* toDBAccessRight(AccessRight access_right_type);
 class IStream;
 
 struct PolicySerializable : public Policy, ISerializable {
-    PolicySerializable();
-    explicit PolicySerializable(const Policy &);
-    explicit PolicySerializable(IStream &);
-    void Serialize(IStream &) const;
+    PolicySerializable() {};
+    explicit PolicySerializable(const Policy &policy) : Policy(policy) {}
+    explicit PolicySerializable(IStream &stream) {
+        Deserialization::Deserialize(stream, password);
+        Deserialization::Deserialize(stream, extractable);
+    }
+    void Serialize(IStream &stream) const {
+        Serialization::Serialize(stream, password);
+        Serialization::Serialize(stream, extractable);
+    }
 };
 
 } // namespace CKM
index 3145ed8..0c59753 100644 (file)
@@ -29,6 +29,8 @@
 #include <string>
 #include <sstream>
 #include <fstream>
+#include <memory>
+#include <stdexcept>
 
 #include <dpl/errno_string.h>
 #include <dpl/log/log.h>