MCPcopy Create free account
hub / github.com/Thalhammer/jwt-cpp / verify

Method verify

include/jwt-cpp/jwt.h:2011–2045  ·  view source on GitHub ↗

* Check if signature is valid * \param data The data to check signature against * \param signature Signature provided by the jwt * \param ec Filled with error details */

Source from the content-addressed store, hash-verified

2009 * \param ec Filled with error details
2010 */
2011 void verify(const std::string& data, const std::string& signature, std::error_code& ec) const {
2012 ec.clear();
2013
2014 auto md_ctx = helper::make_evp_md_ctx();
2015 if (!md_ctx) {
2016 ec = error::signature_verification_error::create_context_failed;
2017 return;
2018 }
2019 EVP_PKEY_CTX* ctx = nullptr;
2020 if (EVP_DigestVerifyInit(md_ctx.get(), &ctx, md(), nullptr, pkey.get()) != 1) {
2021 ec = error::signature_verification_error::verifyinit_failed;
2022 return;
2023 }
2024 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0) {
2025 ec = error::signature_generation_error::rsa_padding_failed;
2026 return;
2027 }
2028// wolfSSL does not require EVP_PKEY_CTX_set_rsa_pss_saltlen. The default behavior
2029// sets the salt length to the hash length. Unlike OpenSSL which exposes this functionality.
2030#ifndef LIBWOLFSSL_VERSION_HEX
2031 if (EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, -1) <= 0) {
2032 ec = error::signature_verification_error::set_rsa_pss_saltlen_failed;
2033 return;
2034 }
2035#endif
2036 if (EVP_DigestUpdate(md_ctx.get(), data.data(), data.size()) != 1) {
2037 ec = error::signature_verification_error::verifyupdate_failed;
2038 return;
2039 }
2040
2041 if (EVP_DigestVerifyFinal(md_ctx.get(), (unsigned char*)signature.data(), signature.size()) <= 0) {
2042 ec = error::signature_verification_error::verifyfinal_failed;
2043 return;
2044 }
2045 }
2046 /**
2047 * Returns the algorithm name provided to the constructor
2048 * \return algorithm's name

Callers

nothing calls this directly

Calls 6

make_evp_md_ctxFunction · 0.85
EVP_DigestVerifyInitFunction · 0.85
EVP_DigestUpdateFunction · 0.85
EVP_DigestVerifyFinalFunction · 0.85
clearMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected