@@ -3113,12 +3113,6 @@ namespace jwt {
3113
3113
};
3114
3114
} // namespace verify_ops
3115
3115
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" }}};
3122
3116
/* *
3123
3117
* \brief JSON Web Key
3124
3118
*
@@ -3355,11 +3349,6 @@ namespace jwt {
3355
3349
3356
3350
std::string get_oct_key () const { return k.get_symmetric_key (); }
3357
3351
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
-
3363
3352
private:
3364
3353
template <typename Decode>
3365
3354
static std::shared_ptr<EVP_PKEY> build_rsa_key (const details::map_of_claims<json_traits>& claims,
@@ -3468,6 +3457,12 @@ namespace jwt {
3468
3457
Clock clock;
3469
3458
// / Supported algorithms
3470
3459
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" }}};
3471
3466
3472
3467
typedef std::vector<jwt::jwk<json_traits>> key_list;
3473
3468
// / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3483,8 +3478,13 @@ namespace jwt {
3483
3478
}
3484
3479
}
3485
3480
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 {
3488
3488
ec.clear ();
3489
3489
algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
3490
3490
if (it == supported_alg.end ()) {
@@ -3743,7 +3743,7 @@ namespace jwt {
3743
3743
if (key_set_it != keys.end ()) {
3744
3744
const key_list& keys = key_set_it->second ;
3745
3745
for (const auto & key : keys) {
3746
- if (key. supports ( algo)) {
3746
+ if (is_valid_combination (key, algo)) {
3747
3747
key_found = true ;
3748
3748
auto alg = from_key_and_alg (key, algo, ec);
3749
3749
alg->verify (data, sig, ec);
0 commit comments