@@ -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 class key {
34383427 public:
@@ -3575,6 +3564,12 @@ namespace jwt {
35753564 Clock clock;
35763565 // / Supported algorithms
35773566 std::unordered_map<std::string, std::shared_ptr<algo_base>> algs;
3567+ using alg_name = std::string;
3568+ using alg_list = std::vector<alg_name>;
3569+ using algorithms = std::unordered_map<std::string, alg_list>;
3570+ algorithms supported_alg = {{" RSA" , {" RS256" , " RS384" , " RS512" , " PS256" , " PS384" , " PS512" }},
3571+ {" EC" , {" ES256" , " ES384" , " ES512" , " ES256K" }},
3572+ {" oct" , {" HS256" , " HS384" , " HS512" }}};
35783573
35793574 typedef std::vector<jwt::jwk<json_traits>> key_list;
35803575 // / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3590,8 +3585,13 @@ namespace jwt {
35903585 }
35913586 }
35923587
3593- static inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3594- const std::string& alg_name, std::error_code& ec) {
3588+ bool is_valid_combination (const jwt::jwk<json_traits>& key, const std::string& alg_name) const {
3589+ const alg_list& x = supported_alg.find (key.get_key_type ())->second ;
3590+ return std::find (x.cbegin (), x.cend (), alg_name) != x.cend ();
3591+ }
3592+
3593+ inline std::unique_ptr<algo_base> from_key_and_alg (const jwt::jwk<json_traits>& key,
3594+ const std::string& alg_name, std::error_code& ec) const {
35953595 ec.clear ();
35963596 algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
35973597 if (it == supported_alg.end ()) {
@@ -3855,7 +3855,7 @@ namespace jwt {
38553855 if (key_set_it != keys.end ()) {
38563856 const key_list& keys = key_set_it->second ;
38573857 for (const auto & key : keys) {
3858- if (key. supports ( algo)) {
3858+ if (is_valid_combination (key, algo)) {
38593859 key_found = true ;
38603860 auto alg = from_key_and_alg (key, algo, ec);
38613861 alg->verify (data, sig, ec);
0 commit comments