Populate claims set back when decoding

This commit is contained in:
Arun M 2017-12-14 21:20:04 +05:30
parent 6f495c2c16
commit 912e4b5ff9
5 changed files with 12 additions and 8 deletions

View file

@ -51,6 +51,8 @@ struct DecodeErrorCategory: std::error_category
return "type mismatch";
case DecodeErrc::JsonParseError:
return "json parse failed";
case DecodeErrc::DuplClaims:
return "duplicate claims";
};
assert (0 && "Code not reached");

View file

@ -101,9 +101,15 @@ void jwt_payload::decode(const string_view enc_str, std::error_code& ec) noexcep
ec = DecodeErrc::JsonParseError;
return;
}
//populate the claims set
for (auto it = payload_.begin(); it != payload_.end(); ++it) {
auto ret = claim_names_.insert(it.key());
if (!ret.second) {
ec = DecodeErrc::DuplClaims;
break;
}
}
//validate the fields
//TODO:
return;
}
@ -429,9 +435,7 @@ jwt_object decode(const string_view enc_str,
.get_claim_value(registered_claims::expiration)
.get<uint64_t>();
std::cout << curr_time << " :: " << p_exp << std::endl;
if (p_exp < curr_time) {
if (p_exp < (curr_time + dparams.leeway)) {
throw VerificationError("Token expired");
}
}