src: Fix token68 decoding

This commit is contained in:
Tatsuhiro Tsujikawa 2013-11-09 16:18:01 +09:00
parent 415b8ed674
commit b405b4bc9f
4 changed files with 18 additions and 2 deletions

View File

@ -93,7 +93,9 @@ int main(int argc, char* argv[])
shrpx::test_downstream_get_norm_response_header) ||
!CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) ||
!CU_add_test(pSuite, "util_inp_strlower",
shrpx::test_util_inp_strlower)) {
shrpx::test_util_inp_strlower) ||
!CU_add_test(pSuite, "util_to_base64",
shrpx::test_util_to_base64)) {
CU_cleanup_registry();
return CU_get_error();
}

View File

@ -283,7 +283,9 @@ void to_base64(std::string& token68str)
break;
}
}
token68str += std::string(4 - token68str.size() % 4, '=');
if(token68str.size() & 0x3) {
token68str.append(4 - (token68str.size() & 0x3), '=');
}
return;
}

View File

@ -71,4 +71,15 @@ void test_util_inp_strlower(void)
CU_ASSERT("" == a);
}
void test_util_to_base64(void)
{
std::string x = "AAA--B_";
util::to_base64(x);
CU_ASSERT("AAA++B/=" == x);
x = "AAA--B_B";
util::to_base64(x);
CU_ASSERT("AAA++B/B" == x);
}
} // namespace shrpx

View File

@ -29,6 +29,7 @@ namespace shrpx {
void test_util_streq(void);
void test_util_inp_strlower(void);
void test_util_to_base64(void);
} // namespace shrpx