<commit_before>#include <qpdf/QPDFCrypto_openssl.hh>

#include <cstring>
#include <stdexcept>

#include <qpdf/QIntC.hh>


static void
bad_bits(int bits)
{
    throw std::logic_error(
        std::string("unsupported key length: ") + std::to_string(bits));
}

static void
check_openssl(int status)
{
    if (status != 1)
    {
        throw std::runtime_error("openssl error");
    }
}

QPDFCrypto_openssl::QPDFCrypto_openssl() :
    md_ctx(EVP_MD_CTX_new()), cipher_ctx(EVP_CIPHER_CTX_new())
{<commit_msg>Include detailed OpenSSL error messages<commit_after>#include <qpdf/QPDFCrypto_openssl.hh>

#include <cstring>
#include <stdexcept>
#include <string>

#include <openssl/err.h>

#include <qpdf/QIntC.hh>


static void
bad_bits(int bits)
{
    throw std::logic_error(
        std::string("unsupported key length: ") + std::to_string(bits));
}

static void
check_openssl(int status)
{
    if (status != 1)
    {
        // OpenSSL creates a "queue" of errors; copy the first (innermost)
        // error to the exception message.
        char buf[256] = "";
        ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
        std::string what = "OpenSSL error: ";
        what += buf;
        throw std::runtime_error(what);
    }
    ERR_clear_error();
}

QPDFCrypto_openssl::QPDFCrypto_openssl() :
    md_ctx(EVP_MD_CTX_new()), cipher_ctx(EVP_CIPHER_CTX_new())
{
{'fraction_non_alphanumeric': 0.13742690058479531, 'fraction_numerical': 0.003654970760233918, 'mean_word_length': 3.960144927536232, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7531535', 'n_tokens_mistral': 510, 'n_tokens_neox': 494, 'n_words': 96}