Detemplate SecurePipe
There is only one usage of this class in this codebase, so there is no
need for it to be a template. This also has the added benefit of
removing our usage of boost::has_dereference().
Tested: No backend upstream. No way to test. Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia3a4b73c615828c4b4efc4c2dc1f65fe50c27134
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 405de77..4aa712c 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -24,7 +24,6 @@
#include "utils/json_utils.hpp"
#include <boost/process/async_pipe.hpp>
-#include <boost/type_traits/has_dereference.hpp>
#include <boost/url/url_view.hpp>
#include <array>
@@ -503,28 +502,29 @@
};
// Wrapper for boost::async_pipe ensuring proper pipe cleanup
-template <typename Buffer>
-class Pipe
+class SecurePipe
{
public:
using unix_fd = sdbusplus::message::unix_fd;
- Pipe(boost::asio::io_context& io, Buffer&& bufferIn) :
- impl(io), buffer{std::move(bufferIn)}
+ SecurePipe(boost::asio::io_context& io,
+ CredentialsProvider::SecureBuffer&& bufferIn) :
+ impl(io),
+ buffer{std::move(bufferIn)}
{}
- ~Pipe()
+ ~SecurePipe()
{
// Named pipe needs to be explicitly removed
impl.close();
}
- Pipe(const Pipe&) = delete;
- Pipe(Pipe&&) = delete;
- Pipe& operator=(const Pipe&) = delete;
- Pipe& operator=(Pipe&&) = delete;
+ SecurePipe(const SecurePipe&) = delete;
+ SecurePipe(SecurePipe&&) = delete;
+ SecurePipe& operator=(const SecurePipe&) = delete;
+ SecurePipe& operator=(SecurePipe&&) = delete;
- unix_fd fd()
+ unix_fd fd() const
{
return unix_fd{impl.native_source()};
}
@@ -532,30 +532,13 @@
template <typename WriteHandler>
void asyncWrite(WriteHandler&& handler)
{
- impl.async_write_some(data(), std::forward<WriteHandler>(handler));
- }
-
- private:
- // Specialization for pointer types
- template <typename B = Buffer>
- typename std::enable_if<boost::has_dereference<B>::value,
- boost::asio::const_buffer>::type
- data()
- {
- return boost::asio::buffer(*buffer);
- }
-
- template <typename B = Buffer>
- typename std::enable_if<!boost::has_dereference<B>::value,
- boost::asio::const_buffer>::type
- data()
- {
- return boost::asio::buffer(buffer);
+ impl.async_write_some(boost::asio::buffer(*buffer),
+ std::forward<WriteHandler>(handler));
}
const std::string name;
boost::process::async_pipe impl;
- Buffer buffer;
+ CredentialsProvider::SecureBuffer buffer;
};
/**
@@ -568,7 +551,6 @@
const std::string& imageUrl, const bool rw,
std::string&& userName, std::string&& password)
{
- using SecurePipe = Pipe<CredentialsProvider::SecureBuffer>;
constexpr const size_t secretLimit = 1024;
std::shared_ptr<SecurePipe> secretPipe;