Fix bug in splitter

This commit is contained in:
Arun M 2017-11-23 22:04:16 +05:30
parent 9abac3c5d7
commit f8947b53ac
3 changed files with 4 additions and 6 deletions

View file

@ -285,10 +285,8 @@ jwt_object::three_parts(const string_view enc_str)
result[1] = string_view{&enc_str[fpos + 1], spos - fpos - 1};
size_t tpos = enc_str.find_first_of('.', spos + 1);
if (tpos != string_view::npos) {
result[2] = string_view{&enc_str[tpos + 1], tpos - spos - 1};
if (spos != enc_str.length()) {
result[2] = string_view{&enc_str[spos + 1], enc_str.length() - spos};
}
return result;
@ -314,7 +312,7 @@ jwt_object jwt_decode(const string_view encoded_str, const string_view key, bool
//length of the encoded header and payload only.
//Addition of '1' to account for the '.' character.
auto l = parts[0].length() + 1 + parts[1].length();
jsign.verify(jobj.header(), encoded_str.substr(0, l), parts[2]);
auto res = jsign.verify(jobj.header(), encoded_str.substr(0, l), parts[2]);
return jobj;
}

Binary file not shown.

View file

@ -41,7 +41,7 @@ void basic_jwt_object_test()
obj3.secret("secret");
obj3.header().algo("hs256");
std::cout << obj3.signature() << std::endl;
auto dec_obj = jwt::jwt_decode(obj3.signature(), "secret");
}
int main() {