@@ -1025,6 +1025,9 @@ namespace jwt {
1025
1025
throw ecdsa_exception (error::ecdsa_error::invalid_key_size);
1026
1026
}
1027
1027
1028
+ ecdsa (std::shared_ptr<EVP_PKEY> pkey, const EVP_MD* (*md)(), std::string name, size_t siglen)
1029
+ : pkey(pkey), md(md), alg_name(std::move(name)), signature_length(siglen) {}
1030
+
1028
1031
/* *
1029
1032
* Sign jwt data
1030
1033
* \param data The data to sign
@@ -1384,6 +1387,9 @@ namespace jwt {
1384
1387
throw rsa_exception (error::rsa_error::no_key_provided);
1385
1388
}
1386
1389
1390
+ pss (std::shared_ptr<EVP_PKEY> pkey, const EVP_MD* (*md)(), std::string name)
1391
+ : pkey(pkey), md(md), alg_name(std::move(name)) {}
1392
+
1387
1393
/* *
1388
1394
* Sign jwt data
1389
1395
* \param data The data to sign
@@ -1595,6 +1601,8 @@ namespace jwt {
1595
1601
explicit es256 (const std::string& public_key, const std::string& private_key = " " ,
1596
1602
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1597
1603
: ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha256, " ES256" , 64 ) {}
1604
+
1605
+ explicit es256 (std::shared_ptr<EVP_PKEY> pkey) : ecdsa(pkey, EVP_sha256, " ES256" , 64 ) {}
1598
1606
};
1599
1607
/* *
1600
1608
* ES384 algorithm
@@ -1612,6 +1620,8 @@ namespace jwt {
1612
1620
explicit es384 (const std::string& public_key, const std::string& private_key = " " ,
1613
1621
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1614
1622
: ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha384, " ES384" , 96 ) {}
1623
+
1624
+ explicit es384 (std::shared_ptr<EVP_PKEY> pkey) : ecdsa(pkey, EVP_sha384, " ES384" , 96 ) {}
1615
1625
};
1616
1626
/* *
1617
1627
* ES512 algorithm
@@ -1629,6 +1639,8 @@ namespace jwt {
1629
1639
explicit es512 (const std::string& public_key, const std::string& private_key = " " ,
1630
1640
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1631
1641
: ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha512, " ES512" , 132 ) {}
1642
+
1643
+ explicit es512 (std::shared_ptr<EVP_PKEY> pkey) : ecdsa(pkey, EVP_sha512, " ES512" , 132 ) {}
1632
1644
};
1633
1645
/* *
1634
1646
* ES256K algorithm
@@ -1645,6 +1657,8 @@ namespace jwt {
1645
1657
explicit es256k (const std::string& public_key, const std::string& private_key = " " ,
1646
1658
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1647
1659
: ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha256, " ES256K" , 64 ) {}
1660
+
1661
+ explicit es256k (std::shared_ptr<EVP_PKEY> pkey) : ecdsa(pkey, EVP_sha256, " ES256K" , 64 ) {}
1648
1662
};
1649
1663
1650
1664
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
@@ -1707,6 +1721,8 @@ namespace jwt {
1707
1721
explicit ps256 (const std::string& public_key, const std::string& private_key = " " ,
1708
1722
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1709
1723
: pss(public_key, private_key, public_key_password, private_key_password, EVP_sha256, " PS256" ) {}
1724
+
1725
+ explicit ps256 (std::shared_ptr<EVP_PKEY> pkey) : pss(pkey, EVP_sha256, " PS256" ) {}
1710
1726
};
1711
1727
/* *
1712
1728
* PS384 algorithm
@@ -1722,6 +1738,8 @@ namespace jwt {
1722
1738
explicit ps384 (const std::string& public_key, const std::string& private_key = " " ,
1723
1739
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1724
1740
: pss(public_key, private_key, public_key_password, private_key_password, EVP_sha384, " PS384" ) {}
1741
+
1742
+ explicit ps384 (std::shared_ptr<EVP_PKEY> pkey) : pss(pkey, EVP_sha384, " PS384" ) {}
1725
1743
};
1726
1744
/* *
1727
1745
* PS512 algorithm
@@ -1737,6 +1755,8 @@ namespace jwt {
1737
1755
explicit ps512 (const std::string& public_key, const std::string& private_key = " " ,
1738
1756
const std::string& public_key_password = " " , const std::string& private_key_password = " " )
1739
1757
: pss(public_key, private_key, public_key_password, private_key_password, EVP_sha512, " PS512" ) {}
1758
+
1759
+ explicit ps512 (std::shared_ptr<EVP_PKEY> pkey) : pss(pkey, EVP_sha512, " PS512" ) {}
1740
1760
};
1741
1761
} // namespace algorithm
1742
1762
@@ -3480,6 +3500,8 @@ namespace jwt {
3480
3500
return std::make_unique<algo<jwt::algorithm::es384>>(jwt::algorithm::es384 (key.get_pkey ()));
3481
3501
} else if (alg_name == " ES512" ) {
3482
3502
return std::make_unique<algo<jwt::algorithm::es512>>(jwt::algorithm::es512 (key.get_pkey ()));
3503
+ } else if (alg_name == " ES256K" ) {
3504
+ return std::make_unique<algo<jwt::algorithm::es256k>>(jwt::algorithm::es256k (key.get_pkey ()));
3483
3505
} else if (alg_name == " HS256" ) {
3484
3506
return std::make_unique<algo<jwt::algorithm::hs256>>(jwt::algorithm::hs256 (key.get_oct_key ()));
3485
3507
} else if (alg_name == " HS384" ) {
0 commit comments