mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Deprecated BIO_f_base64 from boringssl #61
This commit is contained in:
parent
42fcc915e4
commit
4752d47592
2 changed files with 15 additions and 32 deletions
|
@ -33,19 +33,6 @@ verify_result_t HMACSign<Hasher>::verify(
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
|
|
||||||
BIO_uptr b64{BIO_new(BIO_f_base64()), bio_deletor};
|
|
||||||
if (!b64) {
|
|
||||||
throw MemoryAllocationException("BIO_new failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
BIO* bmem = BIO_new(BIO_s_mem());
|
|
||||||
if (!bmem) {
|
|
||||||
throw MemoryAllocationException("BIO_new failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
BIO_push(b64.get(), bmem);
|
|
||||||
BIO_set_flags(b64.get(), BIO_FLAGS_BASE64_NO_NL);
|
|
||||||
|
|
||||||
unsigned char enc_buf[EVP_MAX_MD_SIZE];
|
unsigned char enc_buf[EVP_MAX_MD_SIZE];
|
||||||
uint32_t enc_buf_len = 0;
|
uint32_t enc_buf_len = 0;
|
||||||
|
|
||||||
|
@ -60,27 +47,23 @@ verify_result_t HMACSign<Hasher>::verify(
|
||||||
ec = AlgorithmErrc::VerificationErr;
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
return {false, ec};
|
return {false, ec};
|
||||||
}
|
}
|
||||||
|
if (enc_buf_len == 0) {
|
||||||
BIO_write(b64.get(), enc_buf, enc_buf_len);
|
|
||||||
(void)BIO_flush(b64.get());
|
|
||||||
|
|
||||||
int len = BIO_pending(bmem);
|
|
||||||
if (len < 0) {
|
|
||||||
ec = AlgorithmErrc::VerificationErr;
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
return {false, ec};
|
return {false, ec};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cbuf;
|
std::string b64_enc_str = jwt::base64_encode((const char*)&enc_buf[0], enc_buf_len);
|
||||||
cbuf.resize(len + 1);
|
|
||||||
|
|
||||||
len = BIO_read(bmem, &cbuf[0], len);
|
if (!b64_enc_str.length()) {
|
||||||
cbuf.resize(len);
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
|
return {false, ec};
|
||||||
|
}
|
||||||
|
|
||||||
// Make the base64 string url safe
|
// Make the base64 string url safe
|
||||||
auto new_len = jwt::base64_uri_encode(&cbuf[0], cbuf.length());
|
auto new_len = jwt::base64_uri_encode(&b64_enc_str[0], b64_enc_str.length());
|
||||||
cbuf.resize(new_len);
|
b64_enc_str.resize(new_len);
|
||||||
|
|
||||||
bool ret = (jwt::string_view{cbuf} == jwt_sign);
|
bool ret = (jwt::string_view{b64_enc_str} == jwt_sign);
|
||||||
|
|
||||||
return { ret, ec };
|
return { ret, ec };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue