@@ -3186,12 +3186,6 @@ namespace jwt {
3186
3186
};
3187
3187
} // namespace verify_ops
3188
3188
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" }}};
3195
3189
/* *
3196
3190
* \brief JSON Web Key
3197
3191
*
@@ -3428,11 +3422,6 @@ namespace jwt {
3428
3422
3429
3423
std::string get_oct_key () const { return k.get_symmetric_key (); }
3430
3424
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
-
3436
3425
private:
3437
3426
class key {
3438
3427
public:
@@ -3575,6 +3564,12 @@ namespace jwt {
3575
3564
Clock clock;
3576
3565
// / Supported algorithms
3577
3566
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" }}};
3578
3573
3579
3574
typedef std::vector<jwt::jwk<json_traits>> key_list;
3580
3575
// / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3590,8 +3585,13 @@ namespace jwt {
3590
3585
}
3591
3586
}
3592
3587
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 {
3595
3595
ec.clear ();
3596
3596
algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
3597
3597
if (it == supported_alg.end ()) {
@@ -3855,7 +3855,7 @@ namespace jwt {
3855
3855
if (key_set_it != keys.end ()) {
3856
3856
const key_list& keys = key_set_it->second ;
3857
3857
for (const auto & key : keys) {
3858
- if (key. supports ( algo)) {
3858
+ if (is_valid_combination (key, algo)) {
3859
3859
key_found = true ;
3860
3860
auto alg = from_key_and_alg (key, algo, ec);
3861
3861
alg->verify (data, sig, ec);
0 commit comments