netipmid: use shared_ptr on messages instead of unique_ptr+references

Messages were being created and held by unique_ptr objects and then
shared via reference. This is dangerous and sidesteps the whole point of
a unique_ptr, which is to enforce single ownership. This replaces the
usage with a shared_ptr, which denotes shared ownership.

Change-Id: I19ed2693f5a0f5ce47d720ed255fa05bdf3844f8
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/message_parsers.hpp b/message_parsers.hpp
index 0dae43b..b38da40 100644
--- a/message_parsers.hpp
+++ b/message_parsers.hpp
@@ -59,7 +59,7 @@
  *         header type. In case of failure nullptr and session header type
  *         would be invalid.
  */
-std::tuple<std::unique_ptr<Message>, SessionHeader>
+std::tuple<std::shared_ptr<Message>, SessionHeader>
     unflatten(std::vector<uint8_t>& inPacket);
 
 /**
@@ -72,8 +72,8 @@
  *
  * @return IPMI packet on success
  */
-std::vector<uint8_t> flatten(Message& outMessage, SessionHeader authType,
-                             session::Session& session);
+std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
+                             SessionHeader authType, session::Session& session);
 
 } // namespace parser
 
@@ -101,7 +101,7 @@
  *
  * @return IPMI message in the packet on success
  */
-std::unique_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
+std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
 
 /**
  * @brief Flatten an IPMI message and generate the IPMI packet with the
@@ -111,7 +111,8 @@
  *
  * @return IPMI packet on success
  */
-std::vector<uint8_t> flatten(Message& outMessage, session::Session& session);
+std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
+                             session::Session& session);
 
 } // namespace ipmi15parser
 
@@ -147,7 +148,7 @@
  *
  * @return IPMI message in the packet on success
  */
-std::unique_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
+std::shared_ptr<Message> unflatten(std::vector<uint8_t>& inPacket);
 
 /**
  * @brief Flatten an IPMI message and generate the IPMI packet with the
@@ -157,7 +158,8 @@
  *
  * @return IPMI packet on success
  */
-std::vector<uint8_t> flatten(Message& outMessage, session::Session& session);
+std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
+                             session::Session& session);
 
 namespace internal
 {
@@ -180,7 +182,8 @@
  *
  */
 bool verifyPacketIntegrity(const std::vector<uint8_t>& packet,
-                           const Message& message, size_t payloadLen);
+                           const std::shared_ptr<Message> message,
+                           size_t payloadLen);
 
 /**
  * @brief Add Integrity data to the outgoing IPMI packet
@@ -189,7 +192,8 @@
  * @param[in] message - IPMI Message populated for the outgoing packet
  * @param[in] payloadLen - Length of the IPMI payload
  */
-void addIntegrityData(std::vector<uint8_t>& packet, const Message& message,
+void addIntegrityData(std::vector<uint8_t>& packet,
+                      const std::shared_ptr<Message> message,
                       size_t payloadLen);
 
 /**
@@ -202,7 +206,8 @@
  * @return on successful completion, return the plain text payload
  */
 std::vector<uint8_t> decryptPayload(const std::vector<uint8_t>& packet,
-                                    const Message& message, size_t payloadLen);
+                                    const std::shared_ptr<Message> message,
+                                    size_t payloadLen);
 
 /**
  * @brief Encrypt the plain text payload for the outgoing IPMI packet
@@ -211,7 +216,7 @@
  *
  * @return on successful completion, return the encrypted payload
  */
-std::vector<uint8_t> encryptPayload(Message& message);
+std::vector<uint8_t> encryptPayload(std::shared_ptr<Message> message);
 
 } // namespace internal