This commit is contained in:
Arun M 2018-10-27 12:08:08 +05:30
commit 6e27aa4c86
2 changed files with 15 additions and 1 deletions

View file

@ -200,7 +200,7 @@ inline std::string base64_decode(const char* in, size_t len)
constexpr static const DMap dmap{};
while (dmap.at(in[bytes_rem - 1]) == -1) { bytes_rem--; }
while (bytes_rem > 0 && dmap.at(in[bytes_rem - 1]) == -1) { bytes_rem--; }
while (bytes_rem > 4)
{

View file

@ -64,6 +64,20 @@ TEST (DecodeTest, DecodeInvalidHeader)
}
TEST (DecodeTest, DecodeEmptyHeader)
{
using namespace jwt::params;
const char* enc_str =
".eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret(""), verify(true));
ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError));
}
TEST (DecodeTest, DecodeInvalidPayload)
{
using namespace jwt::params;