@@ -783,6 +783,40 @@ namespace jwt {
783
783
}
784
784
} // namespace helper
785
785
786
+ class key {
787
+ public:
788
+ static key symmetric (const std::string& bytes) { return key (bytes); }
789
+
790
+ static key asymmetric (std::shared_ptr<EVP_PKEY> pkey) { return key (pkey); }
791
+
792
+ std::string get_symmetric_key () const {
793
+ if (!is_symmetric) { throw std::logic_error (" not a symmetric key" ); }
794
+
795
+ return oct_key;
796
+ }
797
+
798
+ std::shared_ptr<EVP_PKEY> get_asymmetric_key () const {
799
+ if (is_symmetric) { throw std::logic_error (" not an asymmetric key" ); }
800
+
801
+ return pkey;
802
+ }
803
+
804
+ private:
805
+ key (const std::string& key) {
806
+ is_symmetric = true ;
807
+ oct_key = key;
808
+ }
809
+
810
+ key (std::shared_ptr<EVP_PKEY> key) {
811
+ is_symmetric = false ;
812
+ pkey = key;
813
+ }
814
+
815
+ bool is_symmetric;
816
+ std::shared_ptr<EVP_PKEY> pkey;
817
+ std::string oct_key;
818
+ };
819
+
786
820
/* *
787
821
* \brief Various cryptographic algorithms when working with JWT
788
822
*
@@ -3105,7 +3139,7 @@ namespace jwt {
3105
3139
JWT_CLAIM_EXPLICIT jwk (const typename json_traits::value_type& json) : jwk(json_traits::as_object(json)) {}
3106
3140
3107
3141
JWT_CLAIM_EXPLICIT jwk (const typename json_traits::object_type& json)
3108
- : jwk_claims(json), key (build_key(jwk_claims)) {
3142
+ : jwk_claims(json), k (build_key(jwk_claims)) {
3109
3143
// https://datatracker.ietf.org/doc/html/rfc7518#section-6.1
3110
3144
// * indicate required params
3111
3145
// "kty"* : "EC", "RSA", "oct"
@@ -3301,50 +3335,16 @@ namespace jwt {
3301
3335
3302
3336
bool empty () const noexcept { return jwk_claims.empty (); }
3303
3337
3304
- std::shared_ptr<EVP_PKEY> get_pkey () const { return key .get_asymmetric_key (); }
3338
+ std::shared_ptr<EVP_PKEY> get_pkey () const { return k .get_asymmetric_key (); }
3305
3339
3306
- std::string get_oct_key () const { return key .get_symmetric_key (); }
3340
+ std::string get_oct_key () const { return k .get_symmetric_key (); }
3307
3341
3308
3342
bool supports (const std::string& alg_name) const {
3309
3343
const alg_list& x = supported_alg.find (get_key_type ())->second ;
3310
3344
return std::find (x.begin (), x.end (), alg_name) != x.end ();
3311
3345
}
3312
3346
3313
3347
private:
3314
- class key {
3315
- public:
3316
- static key symmetric (const std::string& bytes) { return key (bytes); }
3317
-
3318
- static key asymmetric (std::shared_ptr<EVP_PKEY> pkey) { return key (pkey); }
3319
-
3320
- std::string get_symmetric_key () const {
3321
- if (!is_symmetric) { throw std::logic_error (" not a symmetric key" ); }
3322
-
3323
- return oct_key;
3324
- }
3325
-
3326
- std::shared_ptr<EVP_PKEY> get_asymmetric_key () const {
3327
- if (is_symmetric) { throw std::logic_error (" not an asymmetric key" ); }
3328
-
3329
- return pkey;
3330
- }
3331
-
3332
- private:
3333
- key (const std::string& key) {
3334
- is_symmetric = true ;
3335
- oct_key = key;
3336
- }
3337
-
3338
- key (std::shared_ptr<EVP_PKEY> key) {
3339
- is_symmetric = false ;
3340
- pkey = key;
3341
- }
3342
-
3343
- bool is_symmetric;
3344
- std::shared_ptr<EVP_PKEY> pkey;
3345
- std::string oct_key;
3346
- };
3347
-
3348
3348
static std::shared_ptr<EVP_PKEY> build_rsa_key (const details::map_of_claims<json_traits>& claims) {
3349
3349
EVP_PKEY* evp_key = nullptr ;
3350
3350
auto n = jwt::helper::raw2bn (
@@ -3407,7 +3407,7 @@ namespace jwt {
3407
3407
}
3408
3408
}
3409
3409
3410
- key key ;
3410
+ key k ;
3411
3411
};
3412
3412
3413
3413
/* *
0 commit comments