@@ -3113,12 +3113,6 @@ namespace jwt {
31133113 };
31143114 } // namespace verify_ops
31153115
3116- using alg_name = std::string;
3117- using alg_list = std::vector<alg_name>;
3118- using algorithms = std::unordered_map<std::string, alg_list>;
3119- static const algorithms supported_alg = {{" RSA" , {" RS256" , " RS384" , " RS512" , " PS256" , " PS384" , " PS512" }},
3120- {" EC" , {" ES256" , " ES384" , " ES512" , " ES256K" }},
3121- {" oct" , {" HS256" , " HS384" , " HS512" }}};
31223116 /* *
31233117 * \brief JSON Web Key
31243118 *
@@ -3355,11 +3349,6 @@ namespace jwt {
33553349
33563350 std::string get_oct_key () const { return k.get_symmetric_key (); }
33573351
3358- bool supports (const std::string& alg_name) const {
3359- const alg_list& x = supported_alg.find (get_key_type ())->second ;
3360- return std::find (x.begin (), x.end (), alg_name) != x.end ();
3361- }
3362-
33633352 private:
33643353 template <typename Decode>
33653354 static std::shared_ptr<EVP_PKEY> build_rsa_key (const details::map_of_claims<json_traits>& claims,
@@ -3468,6 +3457,12 @@ namespace jwt {
34683457 Clock clock;
34693458 // / Supported algorithms
34703459 std::unordered_map<std::string, std::shared_ptr<algo_base>> algs;
3460+ using alg_name = std::string;
3461+ using alg_list = std::vector<alg_name>;
3462+ using algorithms = std::unordered_map<std::string, alg_list>;
3463+ algorithms supported_alg = {{" RSA" , {" RS256" , " RS384" , " RS512" , " PS256" , " PS384" , " PS512" }},
3464+ {" EC" , {" ES256" , " ES384" , " ES512" , " ES256K" }},
3465+ {" oct" , {" HS256" , " HS384" , " HS512" }}};
34713466
34723467 typedef std::vector<jwt::jwk<json_traits>> key_list;
34733468 // / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3483,8 +3478,13 @@ namespace jwt {
34833478 }
34843479 }
34853480
3486- static inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3487- const std::string& alg_name, std::error_code& ec) {
3481+ bool is_valid_combination (const jwt::jwk<json_traits>& key, const std::string& alg_name) const {
3482+ const alg_list& x = supported_alg.find (key.get_key_type ())->second ;
3483+ return std::find (x.cbegin (), x.cend (), alg_name) != x.cend ();
3484+ }
3485+
3486+ inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3487+ const std::string& alg_name, std::error_code& ec) const {
34883488 ec.clear ();
34893489 algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
34903490 if (it == supported_alg.end ()) {
@@ -3743,7 +3743,7 @@ namespace jwt {
37433743 if (key_set_it != keys.end ()) {
37443744 const key_list& keys = key_set_it->second ;
37453745 for (const auto & key : keys) {
3746- if (key. supports ( algo)) {
3746+ if (is_valid_combination (key, algo)) {
37473747 key_found = true ;
37483748 auto alg = from_key_and_alg (key, algo, ec);
37493749 alg->verify (data, sig, ec);
0 commit comments