Skip to content

Commit c050d5b

Browse files
committed
validate claims in separate method
1 parent b78d21c commit c050d5b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

include/jwt-cpp/jwt.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,15 @@ namespace jwt {
32873287
/// Supported algorithms
32883288
std::unordered_map<std::string, std::shared_ptr<algo_base>> algs;
32893289

3290+
void verify_claims(const decoded_jwt<json_traits>& jwt, std::error_code& ec) const {
3291+
verify_ops::verify_context<json_traits> ctx{clock.now(), jwt, default_leeway};
3292+
for (auto& c : claims) {
3293+
ctx.claim_key = c.first;
3294+
c.second(ctx, ec);
3295+
if (ec) return;
3296+
}
3297+
}
3298+
32903299
public:
32913300
/**
32923301
* Constructor for building a new verifier instance
@@ -3473,12 +3482,7 @@ namespace jwt {
34733482
algs.at(algo)->verify(data, sig, ec);
34743483
if (ec) return;
34753484

3476-
verify_ops::verify_context<json_traits> ctx{clock.now(), jwt, default_leeway};
3477-
for (auto& c : claims) {
3478-
ctx.claim_key = c.first;
3479-
c.second(ctx, ec);
3480-
if (ec) return;
3481-
}
3485+
verify_claims(jwt, ec);
34823486
}
34833487
};
34843488

0 commit comments

Comments
 (0)