Implement urlsafe base64 decode
base64 decoding comes in two flavors, "normal" which we already
implement, and "url safe" which modifies the alphabet to create base64
encodings that are safe to use in filenames and urls. Functionally this
just involves swapping two characters with underscore and minus in the
encode/decode table. To avoid duplicating a lot of code, this commit
refactors the base64 tables to be generated at compile time.
Tested: Included unit tests pass. No usage until next commit.
Change-Id: I71724fd2e04000f115c22a40d382d411986d7b39
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/test/http/utility_test.cpp b/test/http/utility_test.cpp
index 404700a..f369d8c 100644
--- a/test/http/utility_test.cpp
+++ b/test/http/utility_test.cpp
@@ -32,6 +32,13 @@
EXPECT_EQ(result, "usern4me:passw0rd");
}
+TEST(Utility, Base64DecodeUrlsafe)
+{
+ std::string result;
+ EXPECT_TRUE(base64Decode<true>("-_abcde", result));
+ EXPECT_EQ(result, "\xfb\xf6\x9b\x71\xd7");
+}
+
TEST(Utility, Base64DecodeNonAscii)
{
std::string junkString("\xff\xee\xdd\xcc\x01\x11\x22\x33");