@@ -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
template <typename Decode>
3438
3427
static helper::evp_pkey_handle build_rsa_key (const details::map_of_claims<json_traits>& claims,
@@ -3541,6 +3530,12 @@ namespace jwt {
3541
3530
Clock clock;
3542
3531
// / Supported algorithms
3543
3532
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" }}};
3544
3539
3545
3540
typedef std::vector<jwt::jwk<json_traits>> key_list;
3546
3541
// / https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 - kid to keys
@@ -3556,8 +3551,13 @@ namespace jwt {
3556
3551
}
3557
3552
}
3558
3553
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 {
3561
3561
ec.clear ();
3562
3562
algorithms::const_iterator it = supported_alg.find (key.get_key_type ());
3563
3563
if (it == supported_alg.end ()) {
@@ -3821,7 +3821,7 @@ namespace jwt {
3821
3821
if (key_set_it != keys.end ()) {
3822
3822
const key_list& keys = key_set_it->second ;
3823
3823
for (const auto & key : keys) {
3824
- if (key. supports ( algo)) {
3824
+ if (is_valid_combination (key, algo)) {
3825
3825
key_found = true ;
3826
3826
auto alg = from_key_and_alg (key, algo, ec);
3827
3827
alg->verify (data, sig, ec);
0 commit comments