fix clang-tidy error for overriding destructor
Fixing the error like in
```
/usr/local/include/ipmid/types.hpp:294:28: error: non-constexpr declaration of '~basic_string' follows constexpr declaration [clang-diagnostic-error]
inline ipmi::SecureString::~SecureString()
^
/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/basic_string.h:794:7: note: previous declaration is here
~basic_string()
^
/usr/local/include/ipmid/types.hpp:300:28: error: non-constexpr declaration of '~vector' follows constexpr declaration [clang-diagnostic-error]
inline ipmi::SecureBuffer::~SecureBuffer()
^
/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_vector.h:728:7: note: previous declaration is here
~vector() _GLIBCXX_NOEXCEPT
```
Remove using alias and overriding the destructor and inherent the class
instead.
Change-Id: Ia8972d8b194d8340e67da3e0f53165e42c25f643
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/include/ipmid/types.hpp b/include/ipmid/types.hpp
index fb94aeb..8d65b0f 100644
--- a/include/ipmid/types.hpp
+++ b/include/ipmid/types.hpp
@@ -281,24 +281,42 @@
return std::allocator<T>::deallocate(p, n);
}
};
-using SecureString =
+
+using SecureStringBase =
std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
+class SecureString : public SecureStringBase
+{
+ public:
+ using SecureStringBase::basic_string;
+ SecureString(const SecureStringBase& other) : SecureStringBase(other){};
+ SecureString(SecureString&) = default;
+ SecureString(const SecureString&) = default;
+ SecureString(SecureString&&) = default;
+ SecureString& operator=(SecureString&&) = default;
+ SecureString& operator=(const SecureString&) = default;
-using SecureBuffer = std::vector<uint8_t, SecureAllocator<uint8_t>>;
+ ~SecureString()
+ {
+ OPENSSL_cleanse(&((*this)[0]), this->size());
+ }
+};
+using SecureBufferBase = std::vector<uint8_t, SecureAllocator<uint8_t>>;
+
+class SecureBuffer : public SecureBufferBase
+{
+ public:
+ using SecureBufferBase::vector;
+ SecureBuffer(const SecureBufferBase& other) : SecureBufferBase(other){};
+ SecureBuffer(SecureBuffer&) = default;
+ SecureBuffer(const SecureBuffer&) = default;
+ SecureBuffer(SecureBuffer&&) = default;
+ SecureBuffer& operator=(SecureBuffer&&) = default;
+ SecureBuffer& operator=(const SecureBuffer&) = default;
+
+ ~SecureBuffer()
+ {
+ OPENSSL_cleanse(&((*this)[0]), this->size());
+ }
+};
} // namespace ipmi
-
-namespace std
-{
-template <>
-inline ipmi::SecureString::~SecureString()
-{
- OPENSSL_cleanse(&((*this)[0]), this->size());
-}
-
-template <>
-inline ipmi::SecureBuffer::~SecureBuffer()
-{
- OPENSSL_cleanse(&((*this)[0]), this->size());
-}
-} // namespace std