Add a SecureBuffer class
SecureBuffer is like SecureString, but a specialization of
std::vector<uint8_t> that cleans up after itself
Tested: Executed various ipmi commands to see that they still work
Change-Id: Ifd255ef682d6e46d981de6a5a294d12f3666698b
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp
index 808d96b..8cb9192 100644
--- a/include/ipmid/message.hpp
+++ b/include/ipmid/message.hpp
@@ -21,6 +21,7 @@
#include <exception>
#include <ipmid/api-types.hpp>
#include <ipmid/message/types.hpp>
+#include <ipmid/types.hpp>
#include <memory>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/connection.hpp>
@@ -115,7 +116,7 @@
Payload(Payload&&) = default;
Payload& operator=(Payload&&) = default;
- explicit Payload(std::vector<uint8_t>&& data) : raw(std::move(data))
+ explicit Payload(SecureBuffer&& data) : raw(std::move(data))
{
}
@@ -480,7 +481,7 @@
// partial bytes in the form of bits
fixed_uint_t<details::bitStreamSize> bitStream;
size_t bitCount = 0;
- std::vector<uint8_t> raw;
+ SecureBuffer raw;
size_t rawIndex = 0;
bool trailingOk = true;
bool unpackCheck = false;
@@ -594,8 +595,8 @@
using ptr = std::shared_ptr<Request>;
- explicit Request(Context::ptr context, std::vector<uint8_t>&& d) :
- payload(std::forward<std::vector<uint8_t>>(d)), ctx(context)
+ explicit Request(Context::ptr context, SecureBuffer&& d) :
+ payload(std::forward<SecureBuffer>(d)), ctx(context)
{
}
diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp
index 598e650..efafd3d 100644
--- a/include/ipmid/message/pack.hpp
+++ b/include/ipmid/message/pack.hpp
@@ -250,6 +250,22 @@
}
};
+/** @brief Specialization of PackSingle for SecureBuffer */
+template <>
+struct PackSingle<SecureBuffer>
+{
+ static int op(Payload& p, const SecureBuffer& t)
+ {
+ if (p.bitCount != 0)
+ {
+ return 1;
+ }
+ p.raw.reserve(p.raw.size() + t.size());
+ p.raw.insert(p.raw.end(), t.begin(), t.end());
+ return 0;
+ }
+};
+
/** @brief Specialization of PackSingle for std::string_view */
template <>
struct PackSingle<std::string_view>
diff --git a/include/ipmid/message/unpack.hpp b/include/ipmid/message/unpack.hpp
index d9ccba4..4ac4916 100644
--- a/include/ipmid/message/unpack.hpp
+++ b/include/ipmid/message/unpack.hpp
@@ -324,6 +324,20 @@
}
};
+/** @brief Specialization of UnpackSingle for SecureBuffer */
+template <>
+struct UnpackSingle<SecureBuffer>
+{
+ static int op(Payload& p, SecureBuffer& t)
+ {
+ // copy out the remainder of the message
+ t.reserve(p.raw.size() - p.rawIndex);
+ t.insert(t.begin(), p.raw.begin() + p.rawIndex, p.raw.end());
+ p.rawIndex = p.raw.size();
+ return 0;
+ }
+};
+
/** @brief Specialization of UnpackSingle for Payload */
template <>
struct UnpackSingle<Payload>
diff --git a/include/ipmid/types.hpp b/include/ipmid/types.hpp
index 1705335..9c59ea0 100644
--- a/include/ipmid/types.hpp
+++ b/include/ipmid/types.hpp
@@ -259,13 +259,21 @@
using SecureString =
std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
+using SecureBuffer = std::vector<uint8_t, SecureAllocator<uint8_t>>;
+
} // 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
diff --git a/ipmid-new.cpp b/ipmid-new.cpp
index b507cb3..88a51b5 100644
--- a/ipmid-new.cpp
+++ b/ipmid-new.cpp
@@ -472,11 +472,11 @@
/* called from sdbus async server context */
auto executionEntry(boost::asio::yield_context yield,
sdbusplus::message::message& m, NetFn netFn, uint8_t lun,
- Cmd cmd, std::vector<uint8_t>& data,
+ Cmd cmd, ipmi::SecureBuffer& data,
std::map<std::string, ipmi::Value>& options)
{
const auto dbusResponse =
- [netFn, lun, cmd](Cc cc, const std::vector<uint8_t>& data = {}) {
+ [netFn, lun, cmd](Cc cc, const ipmi::SecureBuffer& data = {}) {
constexpr uint8_t netFnResponse = 0x01;
uint8_t retNetFn = netFn | netFnResponse;
return std::make_tuple(retNetFn, lun, cmd, cc, data);
@@ -564,7 +564,7 @@
channel, userId, sessionId,
privilege, rqSA, hostIdx, yield);
auto request = std::make_shared<ipmi::message::Request>(
- ctx, std::forward<std::vector<uint8_t>>(data));
+ ctx, std::forward<ipmi::SecureBuffer>(data));
message::Response::ptr response = executeIpmiCommand(request);
return dbusResponse(response->cc, response->payload.raw);
@@ -770,14 +770,14 @@
boost::asio::yield_context yield) {
sdbusplus::message::message m{std::move(b)};
unsigned char seq = 0, netFn = 0, lun = 0, cmd = 0;
- std::vector<uint8_t> data;
+ ipmi::SecureBuffer data;
m.read(seq, netFn, lun, cmd, data);
std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
auto ctx = std::make_shared<ipmi::Context>(
bus, netFn, lun, cmd, 0, 0, 0, ipmi::Privilege::Admin, 0, 0, yield);
auto request = std::make_shared<ipmi::message::Request>(
- ctx, std::forward<std::vector<uint8_t>>(data));
+ ctx, std::forward<ipmi::SecureBuffer>(data));
ipmi::message::Response::ptr response =
ipmi::executeIpmiCommand(request);
diff --git a/test/Makefile.am b/test/Makefile.am
index ff6d910..89f4fc6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -64,6 +64,7 @@
-lsdbusplus \
-lsystemd \
-pthread \
+ $(CRYPTO_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
$(OESDK_TESTCASE_FLAGS) \
$(CODE_COVERAGE_LDFLAGS)
diff --git a/test/message/pack.cpp b/test/message/pack.cpp
index 9e88f2b..2eae1ec 100644
--- a/test/message/pack.cpp
+++ b/test/message/pack.cpp
@@ -28,7 +28,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04};
+ ipmi::SecureBuffer k = {0x04};
ASSERT_EQ(p.raw, k);
}
@@ -40,7 +40,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04, 0x86};
+ ipmi::SecureBuffer k = {0x04, 0x86};
ASSERT_EQ(p.raw, k);
}
@@ -52,7 +52,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer k = {0x04, 0x86, 0x00, 0x02};
ASSERT_EQ(p.raw, k);
}
@@ -64,7 +64,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22, 0x11};
+ ipmi::SecureBuffer k = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22, 0x11};
ASSERT_EQ(p.raw, k);
}
@@ -76,7 +76,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), types::nrFixedBits<decltype(v)> / CHAR_BIT);
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x58, 0x23, 0x11};
+ ipmi::SecureBuffer k = {0x58, 0x23, 0x11};
ASSERT_EQ(p.raw, k);
}
@@ -93,7 +93,7 @@
types::nrFixedBits<decltype(v2)>) /
CHAR_BIT);
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0xc9};
+ ipmi::SecureBuffer k = {0xc9};
ASSERT_EQ(p.raw, k);
}
@@ -108,7 +108,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(uint8_t));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0xc9};
+ ipmi::SecureBuffer k = {0xc9};
ASSERT_EQ(p.raw, k);
}
@@ -122,7 +122,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() / CHAR_BIT);
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0xc9};
+ ipmi::SecureBuffer k = {0xc9};
ASSERT_EQ(p.raw, k);
}
@@ -137,7 +137,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), (v1.size() + v2.size()) / CHAR_BIT);
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0xc9};
+ ipmi::SecureBuffer k = {0xc9};
ASSERT_EQ(p.raw, k);
}
@@ -152,7 +152,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() / CHAR_BIT);
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer k = {0x04, 0x86, 0x00, 0x02};
ASSERT_EQ(p.raw, k);
}
@@ -165,7 +165,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(uint16_t) + sizeof(char));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x04, 0x86, 0x41};
+ ipmi::SecureBuffer k = {0x04, 0x86, 0x41};
ASSERT_EQ(p.raw, k);
}
@@ -178,7 +178,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
+ ipmi::SecureBuffer k = {0x02, 0x00, 0x86, 0x04};
ASSERT_EQ(p.raw, k);
}
@@ -197,8 +197,8 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
+ ipmi::SecureBuffer k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
ASSERT_EQ(p.raw, k);
}
@@ -217,8 +217,8 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
+ ipmi::SecureBuffer k = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
ASSERT_EQ(p.raw, k);
}
@@ -231,7 +231,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), v.size() * sizeof(v[0]));
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
+ ipmi::SecureBuffer k = {0x02, 0x00, 0x86, 0x04};
ASSERT_EQ(p.raw, k);
}
@@ -239,21 +239,21 @@
{
ipmi::message::Payload p;
EXPECT_EQ(p.pack(true, std::vector<uint8_t>{1}), 1);
- EXPECT_EQ(p.raw, std::vector<uint8_t>{0b1});
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer{0b1});
}
TEST(PackBasics, StringView)
{
ipmi::message::Payload p;
EXPECT_EQ(p.pack(std::string_view{"\x24\x30\x11"}), 0);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0x24, 0x30, 0x11}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0x24, 0x30, 0x11}));
}
TEST(PackBasics, StringViewUnaligned)
{
ipmi::message::Payload p;
EXPECT_EQ(p.pack(true, std::string_view{"abc"}), 1);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1}));
}
TEST(PackBasics, OptionalEmpty)
@@ -265,7 +265,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), 0);
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {};
+ ipmi::SecureBuffer k = {};
ASSERT_EQ(p.raw, k);
}
@@ -278,7 +278,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(uint32_t));
// check that the bytes were correctly packed (in byte order)
- std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
+ ipmi::SecureBuffer k = {0x02, 0x00, 0x86, 0x04};
ASSERT_EQ(p.raw, k);
}
@@ -287,14 +287,14 @@
ipmi::message::Payload p;
EXPECT_EQ(p.pack(true), 0);
EXPECT_EQ(p.pack(ipmi::message::Payload({0x24, 0x30})), 0);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1, 0x24, 0x30}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1, 0x24, 0x30}));
}
TEST(PackBasics, PayloadUnaligned)
{
ipmi::message::Payload p;
EXPECT_EQ(p.pack(true, ipmi::message::Payload({0x24})), 1);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1}));
}
TEST(PackBasics, PayloadOtherUnaligned)
@@ -303,7 +303,7 @@
q.appendBits(1, 1);
EXPECT_EQ(p.pack(true), 0);
EXPECT_EQ(p.pack(q), 1);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1}));
}
TEST(PackBasics, PrependPayload)
@@ -311,7 +311,7 @@
ipmi::message::Payload p;
EXPECT_EQ(p.pack(true), 0);
EXPECT_EQ(p.prepend(ipmi::message::Payload({0x24, 0x30})), 0);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0x24, 0x30, 0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0x24, 0x30, 0b1}));
}
TEST(PackBasics, PrependPayloadUnaligned)
@@ -320,7 +320,7 @@
p.appendBits(1, 1);
EXPECT_EQ(p.prepend(ipmi::message::Payload({0x24})), 1);
p.drain();
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1}));
}
TEST(PackBasics, PrependPayloadOtherUnaligned)
@@ -329,7 +329,7 @@
q.appendBits(1, 1);
EXPECT_EQ(p.pack(true), 0);
EXPECT_EQ(p.prepend(q), 1);
- EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+ EXPECT_EQ(p.raw, ipmi::SecureBuffer({0b1}));
}
TEST(PackAdvanced, Uints)
@@ -348,8 +348,8 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v1) + sizeof(v2) + sizeof(v3) + sizeof(v4));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
- 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
+ ipmi::SecureBuffer k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
+ 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
ASSERT_EQ(p.raw, k);
}
@@ -370,8 +370,8 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(v1) + sizeof(v2) + sizeof(v3) + sizeof(v4));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
- 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
+ ipmi::SecureBuffer k = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
+ 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
ASSERT_EQ(p.raw, k);
}
@@ -386,7 +386,7 @@
ASSERT_EQ(p.size(), sizeof(data));
// check that the bytes were correctly packed packed (LSB first)
- std::vector<uint8_t> k = {2, 4};
+ ipmi::SecureBuffer k = {2, 4};
ASSERT_EQ(p.raw, k);
}
@@ -410,7 +410,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(uint16_t));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x9e, 0xdb};
+ ipmi::SecureBuffer k = {0x9e, 0xdb};
ASSERT_EQ(p.raw, k);
}
@@ -444,7 +444,7 @@
// check that the number of bytes matches
ASSERT_EQ(p.size(), sizeof(uint64_t));
// check that the bytes were correctly packed (LSB first)
- std::vector<uint8_t> k = {0x96, 0xd2, 0x2a, 0xcd, 0xd3, 0x3b, 0xbc, 0x9d};
+ ipmi::SecureBuffer k = {0x96, 0xd2, 0x2a, 0xcd, 0xd3, 0x3b, 0xbc, 0x9d};
ASSERT_EQ(p.raw, k);
}
@@ -485,13 +485,13 @@
sizeof(uint16_t));
uint8_t protocol_channel =
(static_cast<uint8_t>(protocol) << 4) | static_cast<uint8_t>(channel);
- std::vector<uint8_t> k = {handle, maxSessions, currentSessions, userID,
- priv, protocol_channel,
- // ip addr
- 0x05, 0x01, 0x01, 0x0a,
- // mac addr
- 0, 0, 0, 0, 0, 0,
- // port
- 0x1f, 0xd8};
+ ipmi::SecureBuffer k = {handle, maxSessions, currentSessions, userID, priv,
+ protocol_channel,
+ // ip addr
+ 0x05, 0x01, 0x01, 0x0a,
+ // mac addr
+ 0, 0, 0, 0, 0, 0,
+ // port
+ 0x1f, 0xd8};
ASSERT_EQ(p.raw, k);
}
diff --git a/test/message/payload.cpp b/test/message/payload.cpp
index 56d8d41..7c55e7e 100644
--- a/test/message/payload.cpp
+++ b/test/message/payload.cpp
@@ -25,9 +25,9 @@
TEST(Payload, InputSize)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
size_t input_size = i.size();
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
ASSERT_EQ(input_size, p.size());
}
@@ -35,7 +35,7 @@
{
ipmi::message::Payload p;
ASSERT_EQ(0, p.size());
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
p.pack(i);
ASSERT_EQ(i.size(), p.size());
p.pack(i);
@@ -45,7 +45,7 @@
TEST(Payload, Resize)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
ipmi::message::Payload p;
p.pack(i);
p.resize(16);
@@ -54,7 +54,7 @@
TEST(Payload, Data)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
ipmi::message::Payload p;
p.pack(i);
ASSERT_NE(nullptr, p.data());
@@ -92,7 +92,7 @@
ASSERT_EQ(p.bitCount, 0);
// appended 8 bits, should be one byte
ASSERT_EQ(p.size(), 1);
- std::vector<uint8_t> k1 = {0b11100101};
+ ipmi::SecureBuffer k1 = {0b11100101};
ASSERT_EQ(p.raw, k1);
p.appendBits(7, 0b1110111);
// appended 7 more bits, should still be one byte
@@ -100,7 +100,7 @@
p.drain();
// drain forces padding; should be two bytes now
ASSERT_EQ(p.size(), 2);
- std::vector<uint8_t> k2 = {0b11100101, 0b01110111};
+ ipmi::SecureBuffer k2 = {0b11100101, 0b01110111};
ASSERT_EQ(p.raw, k2);
}
@@ -113,7 +113,7 @@
ASSERT_EQ(p.size(), 2);
ASSERT_EQ(p.bitCount, 0);
ASSERT_EQ(p.bitStream, 0);
- std::vector<uint8_t> k1 = {0b11001111, 0b10110100};
+ ipmi::SecureBuffer k1 = {0b11001111, 0b10110100};
ASSERT_EQ(p.raw, k1);
}
@@ -126,7 +126,7 @@
ASSERT_EQ(p.size(), 2);
ASSERT_EQ(p.bitCount, 0);
ASSERT_EQ(p.bitStream, 0);
- std::vector<uint8_t> k1 = {0b1100111, 0b1011010};
+ ipmi::SecureBuffer k1 = {0b1100111, 0b1011010};
ASSERT_EQ(p.raw, k1);
}
@@ -140,14 +140,14 @@
ASSERT_EQ(p.size(), 1);
ASSERT_EQ(p.bitCount, 7);
ASSERT_EQ(p.bitStream, 0b1011010);
- std::vector<uint8_t> k1 = {0b1100111};
+ ipmi::SecureBuffer k1 = {0b1100111};
ASSERT_EQ(p.raw, k1);
}
TEST(PayloadRequest, Pop)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
const auto& [vb, ve] = p.pop<uint8_t>(4);
std::vector<uint8_t> v(vb, ve);
std::vector<uint8_t> k = {0xbf, 0x04, 0x86, 0x00};
@@ -156,8 +156,8 @@
TEST(PayloadRequest, FillBits)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(5);
ASSERT_FALSE(p.unpackError);
ASSERT_EQ(p.bitStream, 0xbf);
@@ -178,24 +178,24 @@
TEST(PayloadRequest, FillBitsTooManyBits)
{
- std::vector<uint8_t> i = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(72);
ASSERT_TRUE(p.unpackError);
}
TEST(PayloadRequest, FillBitsNotEnoughBytes)
{
- std::vector<uint8_t> i = {1, 2, 3, 4};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {1, 2, 3, 4};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(48);
ASSERT_TRUE(p.unpackError);
}
TEST(PayloadRequest, PopBits)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(4);
uint8_t v = p.popBits(4);
ASSERT_FALSE(p.unpackError);
@@ -206,16 +206,16 @@
TEST(PayloadRequest, PopBitsNoFillBits)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.popBits(4);
ASSERT_TRUE(p.unpackError);
}
TEST(PayloadRequest, DiscardBits)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(5);
ASSERT_FALSE(p.unpackError);
ASSERT_EQ(p.bitStream, 0xbf);
@@ -228,8 +228,8 @@
TEST(PayloadRequest, FullyUnpacked)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint32_t v1;
p.unpack(v1);
// still one remaining byte
@@ -249,8 +249,8 @@
TEST(PayloadRequest, ResetInternal)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
p.fillBits(4);
p.unpackError = true;
p.reset();
@@ -265,8 +265,8 @@
// Payload.reset is used to rewind the unpacking to the initial
// state. This is needed so that OEM commands can unpack the group
// number or the IANA to determine which handler needs to be called
- std::vector<uint8_t> i = {0x04, 0x86};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v1;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v1), 0);
@@ -290,8 +290,8 @@
TEST(PayloadRequest, PartialPayload)
{
- std::vector<uint8_t> i = {0xbf, 0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbf, 0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v1;
ipmi::message::Payload localPayload;
// check that the number of bytes matches
diff --git a/test/message/unpack.cpp b/test/message/unpack.cpp
index 7d69218..66c890a 100644
--- a/test/message/unpack.cpp
+++ b/test/message/unpack.cpp
@@ -20,8 +20,8 @@
TEST(Uints, Uint8)
{
- std::vector<uint8_t> i = {0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -34,8 +34,8 @@
TEST(Uints, Uint8TooManyBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -48,8 +48,8 @@
TEST(Uints, Uint8InsufficientBytes)
{
- std::vector<uint8_t> i = {};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v = 0;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -61,8 +61,8 @@
TEST(Uints, Uint16)
{
- std::vector<uint8_t> i = {0x04, 0x86};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint16_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -75,8 +75,8 @@
TEST(Uints, Uint16TooManyBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint16_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -89,8 +89,8 @@
TEST(Uints, Uint16InsufficientBytes)
{
- std::vector<uint8_t> i = {0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint16_t v = 0;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -102,8 +102,8 @@
TEST(Uints, Uint32)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00, 0x02};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00, 0x02};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint32_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -116,8 +116,8 @@
TEST(Uints, Uint32TooManyBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00, 0x02, 0x44};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00, 0x02, 0x44};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint32_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -130,8 +130,8 @@
TEST(Uints, Uint32InsufficientBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint32_t v = 0;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -143,8 +143,8 @@
TEST(Uints, Uint64)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22, 0x11};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22, 0x11};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint64_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -157,9 +157,9 @@
TEST(Uints, Uint64TooManyBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00, 0x02, 0x44,
- 0x33, 0x22, 0x11, 0x55};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00, 0x02, 0x44,
+ 0x33, 0x22, 0x11, 0x55};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint64_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -172,8 +172,8 @@
TEST(Uints, Uint64InsufficientBytes)
{
- std::vector<uint8_t> i = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x04, 0x86, 0x00, 0x02, 0x44, 0x33, 0x22};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint64_t v = 0;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -185,8 +185,8 @@
TEST(Uints, Uint24)
{
- std::vector<uint8_t> i = {0x58, 0x23, 0x11};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x58, 0x23, 0x11};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint24_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -199,8 +199,8 @@
TEST(FixedInts, Uint24TooManyBytes)
{
- std::vector<uint8_t> i = {0x58, 0x23, 0x11, 0x00};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x58, 0x23, 0x11, 0x00};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint24_t v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -213,8 +213,8 @@
TEST(FixedInts, Uint24InsufficientBytes)
{
- std::vector<uint8_t> i = {0x58, 0x23};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x58, 0x23};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint24_t v = 0;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -228,8 +228,8 @@
{
// individual bytes are unpacked low-order-bits first
// v1 will use [2:0], v2 will use [7:3]
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint3_t v1;
uint5_t v2;
// check that the number of bytes matches
@@ -246,8 +246,8 @@
TEST(FixedInts, Uint3Uint4TooManyBits)
{
// high order bit should not get unpacked
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint3_t v1;
uint4_t v2;
// check that the number of bytes matches
@@ -264,8 +264,8 @@
TEST(FixedInts, Uint3Uint6InsufficientBits)
{
// insufficient bits to unpack v2
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint3_t v1;
uint6_t v2;
// check that the number of bytes matches
@@ -283,8 +283,8 @@
{
// individual bytes are unpacked low-order-bits first
// [v8, v7, v6, v5, v4, v3, v2, v1]
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
bool v8, v7, v6, v5;
bool v4, v3, v2, v1;
// check that the number of bytes matches
@@ -309,8 +309,8 @@
// high order bit should not get unpacked
// individual bytes are unpacked low-order-bits first
// [v7, v6, v5, v4, v3, v2, v1]
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
bool v7, v6, v5;
bool v4, v3, v2, v1;
// check that the number of bytes matches
@@ -333,8 +333,8 @@
{
// individual bytes are unpacked low-order-bits first
// [v8, v7, v6, v5, v4, v3, v2, v1]
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
bool v9;
bool v8, v7, v6, v5;
bool v4, v3, v2, v1;
@@ -359,8 +359,8 @@
{
// individual bytes are unpacked low-order-bits first
// a bitset for 8 bits fills the full byte
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<8> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -375,8 +375,8 @@
{
// individual bytes are unpacked low-order-bits first
// a bitset for 8 bits fills the full byte
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<7> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -391,8 +391,8 @@
{
// individual bytes are unpacked low-order-bits first
// a bitset for 8 bits fills the full byte
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<9> v;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -407,8 +407,8 @@
{
// individual bytes are unpacked low-order-bits first
// v1 will use [2:0], v2 will use [7:3]
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<3> v1;
std::bitset<5> v2;
// check that the number of bytes matches
@@ -425,8 +425,8 @@
TEST(Bitsets, Bitset3Bitset4TooManyBits)
{
// high order bit should not get unpacked
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<3> v1;
std::bitset<4> v2;
// check that the number of bytes matches
@@ -443,8 +443,8 @@
TEST(Bitsets, Bitset3Bitset6InsufficientBits)
{
// insufficient bits to unpack v2
- std::vector<uint8_t> i = {0xc9};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xc9};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<3> v1;
std::bitset<6> v2;
// check that the number of bytes matches
@@ -463,8 +463,8 @@
// individual bytes are unpacked low-order-bits first
// v1 will use 4 bytes, but in LSByte first order
// v1[7:0] v1[15:9] v1[23:16] v1[31:24]
- std::vector<uint8_t> i = {0xb4, 0x86, 0x91, 0xc2};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xb4, 0x86, 0x91, 0xc2};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<32> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -478,8 +478,8 @@
TEST(Bitsets, Bitset31TooManyBits)
{
// high order bit should not get unpacked
- std::vector<uint8_t> i = {0xb4, 0x86, 0x91, 0xc2};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xb4, 0x86, 0x91, 0xc2};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<31> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -493,8 +493,8 @@
TEST(Bitsets, Bitset33InsufficientBits)
{
// insufficient bits to unpack v2
- std::vector<uint8_t> i = {0xb4, 0x86, 0x91, 0xc2};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xb4, 0x86, 0x91, 0xc2};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::bitset<33> v;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -508,8 +508,8 @@
TEST(Arrays, Array4xUint8)
{
// an array of bytes will be read verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint8_t, 4> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -524,8 +524,8 @@
{
// last byte should not get unpacked
// an array of bytes will be read verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04, 0x22};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04, 0x22};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint8_t, 4> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -540,8 +540,8 @@
{
// last byte should not get unpacked
// an array of bytes will be read verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint8_t, 4> v;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -562,9 +562,9 @@
// v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
// v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
// v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
- std::vector<uint8_t> i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint32_t, 4> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -585,10 +585,10 @@
// v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
// v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
// v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
- std::vector<uint8_t> i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66,
- 0x44, 0x22, 0x99, 0x77, 0x55, 0x33,
- 0x78, 0x56, 0x34, 0x12, 0xaa};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66,
+ 0x44, 0x22, 0x99, 0x77, 0x55, 0x33,
+ 0x78, 0x56, 0x34, 0x12, 0xaa};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint32_t, 4> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -609,9 +609,9 @@
// v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
// v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
// v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
- std::vector<uint8_t> i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::array<uint32_t, 4> v;
// check that the number of bytes matches
ASSERT_NE(p.unpack(v), 0);
@@ -631,9 +631,9 @@
// v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
// v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
// v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
- std::vector<uint8_t> i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34, 0x12};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<uint32_t> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -656,9 +656,9 @@
// v[1][7:0] v[1][15:9] v[1][23:16] v[1][31:24]
// v[2][7:0] v[2][15:9] v[2][23:16] v[2][31:24]
// v[3][7:0] v[3][15:9] v[3][23:16] v[3][31:24]
- std::vector<uint8_t> i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
- 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x44, 0x33, 0x22, 0x11, 0x88, 0x66, 0x44, 0x22,
+ 0x99, 0x77, 0x55, 0x33, 0x78, 0x56, 0x34};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<uint32_t> v;
// check that the vector unpacks successfully
ASSERT_EQ(p.unpack(v), 0);
@@ -674,8 +674,8 @@
TEST(Vectors, VectorUint8)
{
// a vector of bytes will be unpacked verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<uint8_t> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -689,8 +689,8 @@
TEST(Vectors, VectorEmptyOk)
{
// an empty input vector to show that unpacking elements is okay
- std::vector<uint8_t> i{};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i{};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<uint32_t> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -704,8 +704,8 @@
TEST(Vectors, VectorOfTuplesOk)
{
// a vector of bytes will be unpacked verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<std::tuple<uint8_t, uint8_t>> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -719,8 +719,8 @@
TEST(Vectors, VectorOfTuplesInsufficientBytes)
{
// a vector of bytes will be unpacked verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04, 0xb4};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04, 0xb4};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::vector<std::tuple<uint8_t, uint8_t>> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -739,8 +739,8 @@
TEST(UnpackAdvanced, OptionalOk)
{
// a vector of bytes will be unpacked verbatim, low-order element first
- std::vector<uint8_t> i = {0xbe, 0x02, 0x00, 0x86, 0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0xbe, 0x02, 0x00, 0x86, 0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::optional<std::tuple<uint8_t, uint32_t>> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -754,8 +754,8 @@
TEST(UnpackAdvanced, OptionalInsufficientBytes)
{
// a vector of bytes will be unpacked verbatim, low-order element first
- std::vector<uint8_t> i = {0x02, 0x00, 0x86, 0x04};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x00, 0x86, 0x04};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
std::optional<std::tuple<uint8_t, uint32_t>> v;
// check that the number of bytes matches
ASSERT_EQ(p.unpack(v), 0);
@@ -773,9 +773,9 @@
// v1[7:0] v2[7:0] v2[15:8] v3[7:0] v3[15:8] v3[23:16] v3[31:24]
// v4[7:0] v4[15:8] v4[23:16] v4[31:24]
// v4[39:25] v4[47:40] v4[55:48] v4[63:56]
- std::vector<uint8_t> i = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
- 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
+ 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v1;
uint16_t v2;
uint32_t v3;
@@ -802,9 +802,9 @@
// v1[7:0] v2[7:0] v2[15:8] v3[7:0] v3[15:8] v3[23:16] v3[31:24]
// v4[7:0] v4[15:8] v4[23:16] v4[31:24]
// v4[39:25] v4[47:40] v4[55:48] v4[63:56]
- std::vector<uint8_t> i = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
- 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x02, 0x04, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55,
+ 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint8_t v1;
uint16_t v2;
uint32_t v3;
@@ -832,8 +832,8 @@
// v3[4:0] will use k[0][7:3], v3[6:5] will use k[1][1:0]
// v4 will use k[1][2]
// v5 will use k[1][7:3]
- std::vector<uint8_t> i = {0x9e, 0xdb};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x9e, 0xdb};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint2_t v1;
bool v2;
std::bitset<7> v3;
@@ -871,8 +871,8 @@
// v6[19:12] will use k[5][7:0] v6[27:20] will use k[6][7:0]
// v6[31:28] will use k[7][3:0]
// v7 will use k[7][7:4]
- std::vector<uint8_t> i = {0x96, 0xd2, 0x2a, 0xcd, 0xd3, 0x3b, 0xbc, 0x9d};
- ipmi::message::Payload p(std::forward<std::vector<uint8_t>>(i));
+ ipmi::SecureBuffer i = {0x96, 0xd2, 0x2a, 0xcd, 0xd3, 0x3b, 0xbc, 0x9d};
+ ipmi::message::Payload p(std::forward<ipmi::SecureBuffer>(i));
uint2_t v1;
uint8_t v2;
bool v3;