@@ -543,28 +543,18 @@ namespace jwt {
543543 }
544544
545545 /* *
546- * \brief Convert the certificate provided as base64 DER to PEM.
547- *
548- * This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info
549- * (here)[https://tools.ietf.org/html/rfc7517#section-4.7]
546+ * \brief Convert the certificate provided as DER to PEM.
550547 *
551- * \tparam Decode is callabled, taking a string_type and returns a string_type.
552- * It should ensure the padding of the input and then base64 decode and return
553- * the results.
554- *
555- * \param cert_base64_der_str String containing the certificate encoded as base64 DER
556- * \param decode The function to decode the cert
557- * \param ec error_code for error_detection (gets cleared if no error occures)
548+ * \param cert_der_str String containing the certificate encoded as base64 DER
549+ * \param ec error_code for error_detection (gets cleared if no error occures)
558550 */
559- template <typename Decode>
560- std::string convert_base64_der_to_pem (const std::string& cert_base64_der_str, Decode decode,
561- std::error_code& ec) {
551+ inline std::string convert_der_to_pem (const std::string& cert_der_str, std::error_code& ec) {
562552 ec.clear ();
563- const auto decodedStr = decode (cert_base64_der_str);
564- auto c_str = reinterpret_cast <const unsigned char *>(decodedStr .c_str ());
553+
554+ auto c_str = reinterpret_cast <const unsigned char *>(cert_der_str .c_str ());
565555
566556 std::unique_ptr<X509, decltype (&X509_free)> cert (
567- d2i_X509 (NULL , &c_str, static_cast <int >(decodedStr .size ())), X509_free);
557+ d2i_X509 (NULL , &c_str, static_cast <int >(cert_der_str .size ())), X509_free);
568558 auto certbio = make_mem_buf_bio ();
569559 if (!cert || !certbio) {
570560 ec = error::rsa_error::create_mem_bio_failed;
@@ -586,6 +576,28 @@ namespace jwt {
586576 return {ptr, static_cast <size_t >(len)};
587577 }
588578
579+ /* *
580+ * \brief Convert the certificate provided as base64 DER to PEM.
581+ *
582+ * This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info
583+ * (here)[https://tools.ietf.org/html/rfc7517#section-4.7]
584+ *
585+ * \tparam Decode is callabled, taking a string_type and returns a string_type.
586+ * It should ensure the padding of the input and then base64 decode and return
587+ * the results.
588+ *
589+ * \param cert_base64_der_str String containing the certificate encoded as base64 DER
590+ * \param decode The function to decode the cert
591+ * \param ec error_code for error_detection (gets cleared if no error occures)
592+ */
593+ template <typename Decode>
594+ std::string convert_base64_der_to_pem (const std::string& cert_base64_der_str, Decode decode,
595+ std::error_code& ec) {
596+ ec.clear ();
597+ const auto decoded_str = decode (cert_base64_der_str);
598+ return convert_der_to_pem (decoded_str, ec);
599+ }
600+
589601 /* *
590602 * \brief Convert the certificate provided as base64 DER to PEM.
591603 *
@@ -607,6 +619,21 @@ namespace jwt {
607619 error::throw_if_error (ec);
608620 return res;
609621 }
622+
623+ /* *
624+ * \brief Convert the certificate provided as DER to PEM.
625+ *
626+ * \param cert_der_str String containing the DER certificate
627+ * \param decode The function to decode the cert
628+ * \throw rsa_exception if an error occurred
629+ */
630+ inline std::string convert_der_to_pem (const std::string& cert_der_str) {
631+ std::error_code ec;
632+ auto res = convert_der_to_pem (cert_der_str, ec);
633+ error::throw_if_error (ec);
634+ return res;
635+ }
636+
610637#ifndef JWT_DISABLE_BASE64
611638 /* *
612639 * \brief Convert the certificate provided as base64 DER to PEM.
0 commit comments