diff --git a/lib/webfuse_provider/impl/base64.c b/lib/webfuse_provider/impl/base64.c index fdb22f1..eda4bcd 100644 --- a/lib/webfuse_provider/impl/base64.c +++ b/lib/webfuse_provider/impl/base64.c @@ -1,6 +1,6 @@ #include "webfuse_provider/impl/base64.h" -static const uint8_t wfp_base64_decode_table[256] = { +static const uint8_t wfp_impl_base64_decode_table[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 0 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 1 @@ -22,12 +22,12 @@ static const uint8_t wfp_base64_decode_table[256] = { -size_t wfp_base64_encoded_size(size_t length) +size_t wfp_impl_base64_encoded_size(size_t length) { return ((length + 2) / 3) * 4; } -size_t wfp_base64_encode( +size_t wfp_impl_base64_encode( uint8_t const * data, size_t length, char * buffer, @@ -36,7 +36,7 @@ size_t wfp_base64_encode( // 0 1 2 3 4 5 6 // 0123456789012345678901234567890123456789012345678901234567890123 static char const table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - size_t const length_needed = wfp_base64_encoded_size(length); + size_t const length_needed = wfp_impl_base64_encoded_size(length); if (buffer_size < length_needed) { return 0; @@ -78,7 +78,7 @@ size_t wfp_base64_encode( return out_pos; } -size_t wfp_base64_decoded_size(char const * data, size_t length) +size_t wfp_impl_base64_decoded_size(char const * data, size_t length) { size_t result = 0; if ((length > 0) && ((length % 4) == 0)) @@ -98,14 +98,14 @@ size_t wfp_base64_decoded_size(char const * data, size_t length) return result; } -size_t wfp_base64_decode( +size_t wfp_impl_base64_decode( char const * data, size_t length, uint8_t * buffer, size_t buffer_size) { - uint8_t const * table = wfp_base64_decode_table; - size_t needed_size = wfp_base64_decoded_size(data, length); + uint8_t const * table = wfp_impl_base64_decode_table; + size_t needed_size = wfp_impl_base64_decoded_size(data, length); if ((0 == needed_size) || (buffer_size < needed_size)) { return 0; @@ -146,9 +146,9 @@ size_t wfp_base64_decode( return out_pos; } -extern bool wfp_base64_isvalid(char const * data, size_t length) +extern bool wfp_impl_base64_isvalid(char const * data, size_t length) { - uint8_t const * table = wfp_base64_decode_table; + uint8_t const * table = wfp_impl_base64_decode_table; if ((length == 0) || ((length % 4) != 0)) { diff --git a/lib/webfuse_provider/impl/base64.h b/lib/webfuse_provider/impl/base64.h index a959668..888b4b9 100644 --- a/lib/webfuse_provider/impl/base64.h +++ b/lib/webfuse_provider/impl/base64.h @@ -15,23 +15,23 @@ extern "C" { #endif -extern size_t wfp_base64_encoded_size(size_t length); +extern size_t wfp_impl_base64_encoded_size(size_t length); -extern size_t wfp_base64_encode( +extern size_t wfp_impl_base64_encode( uint8_t const * data, size_t length, char * buffer, size_t buffer_size); -extern size_t wfp_base64_decoded_size(char const * data, size_t length); +extern size_t wfp_impl_base64_decoded_size(char const * data, size_t length); -extern size_t wfp_base64_decode( +extern size_t wfp_impl_base64_decode( char const * data, size_t length, uint8_t * buffer, size_t buffer_size); -extern bool wfp_base64_isvalid(char const * data, size_t length); +extern bool wfp_impl_base64_isvalid(char const * data, size_t length); #ifdef __cplusplus } diff --git a/lib/webfuse_provider/impl/operation/read.c b/lib/webfuse_provider/impl/operation/read.c index 795c662..d9d8043 100644 --- a/lib/webfuse_provider/impl/operation/read.c +++ b/lib/webfuse_provider/impl/operation/read.c @@ -54,9 +54,9 @@ void wfp_impl_respond_read( { if (0 < length) { - size_t const size = wfp_base64_encoded_size(length) + 1; + size_t const size = wfp_impl_base64_encoded_size(length) + 1; char * buffer = malloc(size); - wfp_base64_encode((uint8_t const *) data, length, buffer, size); + wfp_impl_base64_encode((uint8_t const *) data, length, buffer, size); json_t * result = json_object(); json_object_set_new(result, "data", json_string(buffer)); diff --git a/test/webfuse_provider/tests/core/test_base64.cc b/test/webfuse_provider/tests/core/test_base64.cc index 534886e..33e4c25 100644 --- a/test/webfuse_provider/tests/core/test_base64.cc +++ b/test/webfuse_provider/tests/core/test_base64.cc @@ -3,15 +3,15 @@ TEST(Base64, EncodedSize) { - ASSERT_EQ(4, wfp_base64_encoded_size(1)); - ASSERT_EQ(4, wfp_base64_encoded_size(2)); - ASSERT_EQ(4, wfp_base64_encoded_size(3)); + ASSERT_EQ(4, wfp_impl_base64_encoded_size(1)); + ASSERT_EQ(4, wfp_impl_base64_encoded_size(2)); + ASSERT_EQ(4, wfp_impl_base64_encoded_size(3)); - ASSERT_EQ(8, wfp_base64_encoded_size(4)); - ASSERT_EQ(8, wfp_base64_encoded_size(5)); - ASSERT_EQ(8, wfp_base64_encoded_size(6)); + ASSERT_EQ(8, wfp_impl_base64_encoded_size(4)); + ASSERT_EQ(8, wfp_impl_base64_encoded_size(5)); + ASSERT_EQ(8, wfp_impl_base64_encoded_size(6)); - ASSERT_EQ(120, wfp_base64_encoded_size(90)); + ASSERT_EQ(120, wfp_impl_base64_encoded_size(90)); } TEST(Base64, Encode) @@ -19,17 +19,17 @@ TEST(Base64, Encode) char buffer[42]; std::string in = "Hello"; - size_t length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + size_t length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); ASSERT_EQ(8, length); ASSERT_STREQ("SGVsbG8=", buffer); in = "Hello\n"; - length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); ASSERT_EQ(8, length); ASSERT_STREQ("SGVsbG8K", buffer); in = "Blue"; - length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); + length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 42); ASSERT_EQ(8, length); ASSERT_STREQ("Qmx1ZQ==", buffer); } @@ -39,53 +39,53 @@ TEST(Base64, FailedToEncodeBufferTooSmall) char buffer[1]; std::string in = "Hello"; - size_t length = wfp_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1); + size_t length = wfp_impl_base64_encode((uint8_t const*) in.c_str(), in.size(), buffer, 1); ASSERT_EQ(0, length); } TEST(Base64, DecodedSize) { std::string in = "SGVsbG8="; // Hello - size_t length = wfp_base64_decoded_size(in.c_str(), in.size()); + size_t length = wfp_impl_base64_decoded_size(in.c_str(), in.size()); ASSERT_EQ(5, length); in = "SGVsbG8K"; // Hello\n - length = wfp_base64_decoded_size(in.c_str(), in.size()); + length = wfp_impl_base64_decoded_size(in.c_str(), in.size()); ASSERT_EQ(6, length); in = "Qmx1ZQ=="; // Blue - length = wfp_base64_decoded_size(in.c_str(), in.size()); + length = wfp_impl_base64_decoded_size(in.c_str(), in.size()); ASSERT_EQ(4, length); } TEST(Base64, IsValid) { std::string in = "SGVsbG8="; // Hello - ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "SGVsbG8K"; // Hello\n - ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1ZQ=="; // Blue - ASSERT_TRUE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_TRUE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1ZQ=a"; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1ZQ"; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1ZQ="; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1Z==="; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qmx1ZQ?="; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); in = "Qm?1ZQ=="; - ASSERT_FALSE(wfp_base64_isvalid(in.c_str(), in.size())); + ASSERT_FALSE(wfp_impl_base64_isvalid(in.c_str(), in.size())); } TEST(Base64, Decode) @@ -93,19 +93,19 @@ TEST(Base64, Decode) char buffer[42]; std::string in = "SGVsbG8="; // Hello - size_t length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + size_t length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); ASSERT_EQ(5, length); buffer[length] = '\0'; ASSERT_STREQ("Hello", buffer); in = "SGVsbG8K"; // Hello\n - length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); ASSERT_EQ(6, length); buffer[length] = '\0'; ASSERT_STREQ("Hello\n", buffer); in = "Qmx1ZQ=="; // Blue - length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); + length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 42); ASSERT_EQ(4, length); buffer[length] = '\0'; ASSERT_STREQ("Blue", buffer); @@ -116,7 +116,7 @@ TEST(Base64, FailToDecodeBufferTooSmall) char buffer[1]; std::string in = "SGVsbG8="; // Hello - size_t length = wfp_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1); + size_t length = wfp_impl_base64_decode(in.c_str(), in.size(), (uint8_t*) buffer, 1); ASSERT_EQ(0, length); }