summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2023-12-13 21:49:58 +0300
committerEd Tanous <ed@tanous.net>2024-01-22 22:15:20 +0300
commitee192c065cc658b2489d04c791e2fb956a331699 (patch)
tree2c15d1c4b547fc3fcdfbb81ce056787817002e51 /test
parent18f8f608b966c802b3e2a389e3c1ec5a1fd9407b (diff)
downloadbmcweb-ee192c065cc658b2489d04c791e2fb956a331699.tar.xz
Make base64 encoder incremental
As part of https://gerrit.openbmc.org/c/openbmc/bmcweb/+/67667, it would be desirable if we could incrementally encode base64 in chunks. Given that base64 encoding requires encoding 3 characters to 4, there's a possibility that a chunk might not be mod 3 length. This commit moves the base64 encoder into a class that can run incrementally. Tested: Unit tests pass. More tests in next commit. Change-Id: Ic7da3fd4db865c99fcbd96ae06fdecb87628f94c Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'test')
-rw-r--r--test/http/utility_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/http/utility_test.cpp b/test/http/utility_test.cpp
index 5f62d3f3d1..c0b6412af2 100644
--- a/test/http/utility_test.cpp
+++ b/test/http/utility_test.cpp
@@ -71,6 +71,27 @@ TEST(Utility, Base64EncodeString)
EXPECT_EQ(encoded, "ZjAAIEJhcg==");
}
+TEST(Utility, Base64Encoder)
+{
+ using namespace std::string_literals;
+ std::string data = "f0\0 Bar"s;
+ for (size_t chunkSize = 1; chunkSize < 6; chunkSize++)
+ {
+ std::string_view testString(data);
+ std::string out;
+ Base64Encoder encoder;
+ while (!testString.empty())
+ {
+ size_t thisChunk = std::min(testString.size(), chunkSize);
+ encoder.encode(testString.substr(0, thisChunk), out);
+ testString.remove_prefix(thisChunk);
+ }
+
+ encoder.finalize(out);
+ EXPECT_EQ(out, "ZjAAIEJhcg==");
+ }
+}
+
TEST(Utility, Base64EncodeDecodeString)
{
using namespace std::string_literals;