mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 17:28:37 +00:00
Populate claims set back when decoding
This commit is contained in:
parent
6f495c2c16
commit
912e4b5ff9
5 changed files with 12 additions and 8 deletions
|
@ -30,6 +30,7 @@ enum class DecodeErrc
|
||||||
AlgHeaderMiss,
|
AlgHeaderMiss,
|
||||||
TypHeaderMiss,
|
TypHeaderMiss,
|
||||||
TypMismatch,
|
TypMismatch,
|
||||||
|
DuplClaims,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,8 @@ struct DecodeErrorCategory: std::error_category
|
||||||
return "type mismatch";
|
return "type mismatch";
|
||||||
case DecodeErrc::JsonParseError:
|
case DecodeErrc::JsonParseError:
|
||||||
return "json parse failed";
|
return "json parse failed";
|
||||||
|
case DecodeErrc::DuplClaims:
|
||||||
|
return "duplicate claims";
|
||||||
};
|
};
|
||||||
|
|
||||||
assert (0 && "Code not reached");
|
assert (0 && "Code not reached");
|
||||||
|
|
|
@ -101,9 +101,15 @@ void jwt_payload::decode(const string_view enc_str, std::error_code& ec) noexcep
|
||||||
ec = DecodeErrc::JsonParseError;
|
ec = DecodeErrc::JsonParseError;
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,9 +435,7 @@ jwt_object decode(const string_view enc_str,
|
||||||
.get_claim_value(registered_claims::expiration)
|
.get_claim_value(registered_claims::expiration)
|
||||||
.get<uint64_t>();
|
.get<uint64_t>();
|
||||||
|
|
||||||
std::cout << curr_time << " :: " << p_exp << std::endl;
|
if (p_exp < (curr_time + dparams.leeway)) {
|
||||||
|
|
||||||
if (p_exp < curr_time) {
|
|
||||||
throw VerificationError("Token expired");
|
throw VerificationError("Token expired");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,6 @@ public: // Exposed APIs
|
||||||
{
|
{
|
||||||
// Duplicate claim names not allowed
|
// Duplicate claim names not allowed
|
||||||
// if overwrite flag is set to true.
|
// if overwrite flag is set to true.
|
||||||
std::cout << "Adding claim: " << claim_names_.size() << std::endl;
|
|
||||||
auto itr = claim_names_.find(cname);
|
auto itr = claim_names_.find(cname);
|
||||||
if (itr != claim_names_.end() && !overwrite) {
|
if (itr != claim_names_.end() && !overwrite) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -398,8 +397,6 @@ public: // Exposed APIs
|
||||||
//based overload
|
//based overload
|
||||||
bool has_claim(const string_view cname) const noexcept
|
bool has_claim(const string_view cname) const noexcept
|
||||||
{
|
{
|
||||||
std::cout << "CSZ: " << claim_names_.size() << std::endl;
|
|
||||||
for (auto c : claim_names_) std::cout << "Claim: " << c << std::endl;
|
|
||||||
return claim_names_.count(cname);
|
return claim_names_.count(cname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue