@@ -3186,12 +3186,6 @@ namespace jwt {
31863186 };
31873187 } // namespace verify_ops
31883188
3189- using alg_name = std::string;
3190- using alg_list = std::vector<alg_name>;
3191- using algorithms = std::unordered_map<std::string, alg_list>;
3192- static const algorithms supported_alg = {{" RSA" , {" RS256" , " RS384" , " RS512" , " PS256" , " PS384" , " PS512" }},
3193- {" EC" , {" ES256" , " ES384" , " ES512" , " ES256K" }},
3194- {" oct" , {" HS256" , " HS384" , " HS512" }}};
31953189 /* *
31963190 * \brief JSON Web Key
31973191 *
@@ -3428,11 +3422,6 @@ namespace jwt {
34283422
34293423 std::string get_oct_key () const { return k.get_symmetric_key (); }
34303424
3431- bool supports (const std::string& alg_name) const {
3432- const alg_list& x = supported_alg.find (get_key_type ())->second ;
3433- return std::find (x.begin (), x.end (), alg_name) != x.end ();
3434- }
3435-
34363425 private:
34373426 template <typename Decode>
34383427 static helper::evp_pkey_handle build_rsa_key (const details::map_of_claims<json_traits>& claims,
@@ -3541,6 +3530,12 @@ namespace jwt {
35413530 Clock clock;
35423531 // / Supported algorithms
35433532 std::unordered_map<std::string, std::shared_ptr<algo_base>> algs;
3533+ using alg_name = std::string;
3534+ using alg_list = std::vector<alg_name>;
3535+ using algorithms = std::unordered_map<std::string, alg_list>;
3536+ algorithms supported_alg = {{" RSA" , {" RS256" , " RS384" , " RS512" , " PS256" , " PS384" , " PS512" }},
3537+ {" EC" , {" ES256" , " ES384" , " ES512" , " ES256K" }},
3538+ {" oct" , {" HS256" , " HS384" , " HS512" }}};
35443539
35453540 typedef std::vector<jwt::jwk<json_traits>> key_list;
35463541 // / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3556,8 +3551,13 @@ namespace jwt {
35563551 }
35573552 }
35583553
3559- static inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3560- const std::string& alg_name, std::error_code& ec) {
3554+ bool is_valid_combination (const jwt::jwk<json_traits>& key, const std::string& alg_name) const {
3555+ const alg_list& x = supported_alg.find (key.get_key_type ())->second ;
3556+ return std::find (x.cbegin (), x.cend (), alg_name) != x.cend ();
3557+ }
3558+
3559+ inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3560+ const std::string& alg_name, std::error_code& ec) const {
35613561 ec.clear ();
35623562 algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
35633563 if (it == supported_alg.end ()) {
@@ -3821,7 +3821,7 @@ namespace jwt {
38213821 if (key_set_it != keys.end ()) {
38223822 const key_list& keys = key_set_it->second ;
38233823 for (const auto & key : keys) {
3824- if (key. supports ( algo)) {
3824+ if (is_valid_combination (key, algo)) {
38253825 key_found = true ;
38263826 auto alg = from_key_and_alg (key, algo, ec);
38273827 alg->verify (data, sig, ec);
0 commit comments