diff --git a/encryption/encryption.cc b/encryption/encryption.cc index 4846dc7326d..7800cd32ab3 100644 --- a/encryption/encryption.cc +++ b/encryption/encryption.cc @@ -283,21 +283,23 @@ Status AESEncryptionProvider::ReadEncryptionHeader( std::string GetOpenSSLErrors() { std::ostringstream serr; unsigned long l; + const char *file, *data, *func; int line, flags; - const char *file, *data; - bool is_first = true; - while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { - if (is_first) { - is_first = false; - } else { - serr << " "; - } - char buf[256]; - ERR_error_string_n(l, buf, sizeof(buf)); - serr << buf << ":" << file << ":" << line; - if (flags & ERR_TXT_STRING) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000 + l = ERR_peek_last_error_all(&file, &line, &func, &data, &flags); +#else + l = ERR_peek_last_error_line_data(&file, &line, &data, &flags); + func = ERR_func_error_string(l); +#endif + + if (l != 0) { + serr << l << ":" << ERR_lib_error_string(l) << ":" << func << ":" << file + << ":" << line; + if ((flags & ERR_TXT_STRING) && data && *data) { serr << ":" << data; + } else { + serr << ":" << ERR_reason_error_string(l); } } return serr.str();