@@ -175,6 +175,28 @@ TEST(TokenTest, CreateTokenES256) {
175
175
ASSERT_NO_THROW (jwt::verify ().allow_algorithm (jwt::algorithm::es256 (ecdsa256_pub_key, " " , " " , " " )).verify (decoded));
176
176
}
177
177
178
+ TEST (TokenTest, CreateTokenEvpPkeyES256) {
179
+
180
+ auto token = jwt::create ().set_issuer (" auth0" ).set_type (" JWS" ).sign (jwt::algorithm::ecdsa (
181
+ jwt::helper::load_private_ec_key_from_string (ecdsa256_priv_key), EVP_sha256, " ES256" , 64 ));
182
+
183
+ auto decoded = jwt::decode (token);
184
+
185
+ ASSERT_THROW (
186
+ jwt::verify ().allow_algorithm (jwt::algorithm::es256 (ecdsa256_pub_key_invalid, " " , " " , " " )).verify (decoded),
187
+ jwt::error::signature_verification_exception);
188
+ ASSERT_NO_THROW (jwt::verify ().allow_algorithm (jwt::algorithm::es256 (ecdsa256_pub_key, " " , " " , " " )).verify (decoded));
189
+ }
190
+
191
+ TEST (TokenTest, CreateTokenEvpPkeyES256NoPrivate) {
192
+ ASSERT_THROW (
193
+ []() {
194
+ auto token = jwt::create ().set_issuer (" auth0" ).set_type (" JWS" ).sign (jwt::algorithm::ecdsa (
195
+ jwt::helper::load_public_ec_key_from_string (ecdsa256_pub_key), EVP_sha256, " ES256" , 64 ));
196
+ }(),
197
+ jwt::error::signature_generation_exception);
198
+ }
199
+
178
200
TEST (TokenTest, CreateTokenES256NoPrivate) {
179
201
ASSERT_THROW (
180
202
[]() {
@@ -548,6 +570,17 @@ TEST(TokenTest, VerifyTokenES256FailNoKey) {
548
570
jwt::error::ecdsa_exception);
549
571
}
550
572
573
+ TEST (TokenTest, VerifyTokenEvpPkeyES256FailNoKey) {
574
+ ASSERT_THROW (
575
+ []() {
576
+ auto verify = jwt::verify ()
577
+ .allow_algorithm (
578
+ jwt::algorithm::ecdsa (jwt::helper::evp_pkey_handle{nullptr }, EVP_sha256, " ES256" , 64 ))
579
+ .with_issuer (" auth0" );
580
+ }(),
581
+ jwt::error::ecdsa_exception);
582
+ }
583
+
551
584
TEST (TokenTest, VerifyTokenES256) {
552
585
const std::string token = " eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
553
586
" 4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g" ;
@@ -558,6 +591,17 @@ TEST(TokenTest, VerifyTokenES256) {
558
591
verify.verify (decoded_token);
559
592
}
560
593
594
+ TEST (TokenTest, VerifyTokenEvpPkeyES256) {
595
+ const std::string token = " eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
596
+ " 4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g" ;
597
+
598
+ auto verify = jwt::verify ().allow_algorithm (
599
+ jwt::algorithm::ecdsa (jwt::helper::load_public_ec_key_from_string (ecdsa256_pub_key), EVP_sha256, " ES256" , 64 ));
600
+ auto decoded_token = jwt::decode (token);
601
+
602
+ verify.verify (decoded_token);
603
+ }
604
+
561
605
TEST (TokenTest, VerifyTokenES256Fail) {
562
606
const std::string token = " eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
563
607
" 4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g" ;
0 commit comments