static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest,
                                        char *queryfile,
                                        char *CApath, char *CAfile,
                                        char *untrusted,
                                        X509_VERIFY_PARAM *vpm)
{
    TS_VERIFY_CTX *ctx = NULL;
    BIO *input = NULL;
    TS_REQ *request = NULL;
    int ret = 0;
    int f = 0;
    if (data != NULL || digest != NULL) {
        if ((ctx = TS_VERIFY_CTX_new()) == NULL)
            goto err;
        f = TS_VFY_VERSION | TS_VFY_SIGNER;
        if (data != NULL) {
            f |= TS_VFY_DATA;
            if (TS_VERIFY_CTX_set_data(ctx, BIO_new_file(data, "rb")) == NULL)
                goto err;
        } else if (digest != NULL) {
            long imprint_len;
            unsigned char *hexstr = string_to_hex(digest, &imprint_len);
            f |= TS_VFY_IMPRINT;
            if (TS_VERIFY_CTX_set_imprint(ctx, hexstr, imprint_len) == NULL) {
                BIO_printf(bio_err, "invalid digest string\n");
                goto err;
            }
        }
    } else if (queryfile != NULL) {
        if ((input = BIO_new_file(queryfile, "rb")) == NULL)
            goto err;
        if ((request = d2i_TS_REQ_bio(input, NULL)) == NULL)
            goto err;
        if ((ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)) == NULL)
            goto err;
    } else
        return NULL;
    TS_VERIFY_CTX_add_flags(ctx, f | TS_VFY_SIGNATURE);
    if (TS_VERIFY_CTX_set_store(ctx, create_cert_store(CApath, CAfile, vpm))
            == NULL)
        goto err;
    if (untrusted
        && TS_VERIFY_CTS_set_certs(ctx, TS_CONF_load_certs(untrusted)) == NULL)
        goto err;
    ret = 1;
 err:
    if (!ret) {
        TS_VERIFY_CTX_free(ctx);
        ctx = NULL;
    }
    BIO_free_all(input);
    TS_REQ_free(request);
    return ctx;
}
['static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest,\n                                        char *queryfile,\n                                        char *CApath, char *CAfile,\n                                        char *untrusted,\n                                        X509_VERIFY_PARAM *vpm)\n{\n    TS_VERIFY_CTX *ctx = NULL;\n    BIO *input = NULL;\n    TS_REQ *request = NULL;\n    int ret = 0;\n    int f = 0;\n    if (data != NULL || digest != NULL) {\n        if ((ctx = TS_VERIFY_CTX_new()) == NULL)\n            goto err;\n        f = TS_VFY_VERSION | TS_VFY_SIGNER;\n        if (data != NULL) {\n            f |= TS_VFY_DATA;\n            if (TS_VERIFY_CTX_set_data(ctx, BIO_new_file(data, "rb")) == NULL)\n                goto err;\n        } else if (digest != NULL) {\n            long imprint_len;\n            unsigned char *hexstr = string_to_hex(digest, &imprint_len);\n            f |= TS_VFY_IMPRINT;\n            if (TS_VERIFY_CTX_set_imprint(ctx, hexstr, imprint_len) == NULL) {\n                BIO_printf(bio_err, "invalid digest string\\n");\n                goto err;\n            }\n        }\n    } else if (queryfile != NULL) {\n        if ((input = BIO_new_file(queryfile, "rb")) == NULL)\n            goto err;\n        if ((request = d2i_TS_REQ_bio(input, NULL)) == NULL)\n            goto err;\n        if ((ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)) == NULL)\n            goto err;\n    } else\n        return NULL;\n    TS_VERIFY_CTX_add_flags(ctx, f | TS_VFY_SIGNATURE);\n    if (TS_VERIFY_CTX_set_store(ctx, create_cert_store(CApath, CAfile, vpm))\n            == NULL)\n        goto err;\n    if (untrusted\n        && TS_VERIFY_CTS_set_certs(ctx, TS_CONF_load_certs(untrusted)) == NULL)\n        goto err;\n    ret = 1;\n err:\n    if (!ret) {\n        TS_VERIFY_CTX_free(ctx);\n        ctx = NULL;\n    }\n    BIO_free_all(input);\n    TS_REQ_free(request);\n    return ctx;\n}', 'TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)\n{\n    TS_VERIFY_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n    if (ctx == NULL)\n        TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE);\n    return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'BIO *BIO_new_file(const char *filename, const char *mode)\n{\n    BIO  *ret;\n    FILE *file = file_fopen(filename, mode);\n    int fp_flags = BIO_CLOSE;\n    if (strchr(mode, \'b\') == NULL)\n        fp_flags |= BIO_FP_TEXT;\n    if (file == NULL) {\n        SYSerr(SYS_F_FOPEN, get_last_sys_error());\n        ERR_add_error_data(5, "fopen(\'", filename, "\',\'", mode, "\')");\n        if (errno == ENOENT)\n            BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE);\n        else\n            BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB);\n        return (NULL);\n    }\n    if ((ret = BIO_new(BIO_s_file())) == NULL) {\n        fclose(file);\n        return (NULL);\n    }\n    BIO_clear_flags(ret, BIO_FLAGS_UPLINK);\n    BIO_set_fp(ret, file, fp_flags);\n    return (ret);\n}', 'static FILE *file_fopen(const char *filename, const char *mode)\n{\n    FILE *file = NULL;\n#  if defined(_WIN32) && defined(CP_UTF8)\n    int sz, len_0 = (int)strlen(filename) + 1;\n    DWORD flags;\n    if ((sz = MultiByteToWideChar(CP_UTF8, (flags = MB_ERR_INVALID_CHARS),\n                                  filename, len_0, NULL, 0)) > 0 ||\n        (GetLastError() == ERROR_INVALID_FLAGS &&\n         (sz = MultiByteToWideChar(CP_UTF8, (flags = 0),\n                                   filename, len_0, NULL, 0)) > 0)\n        ) {\n        WCHAR wmode[8];\n        WCHAR *wfilename = _alloca(sz * sizeof(WCHAR));\n        if (MultiByteToWideChar(CP_UTF8, flags,\n                                filename, len_0, wfilename, sz) &&\n            MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1,\n                                wmode, OSSL_NELEM(wmode)) &&\n            (file = _wfopen(wfilename, wmode)) == NULL &&\n            (errno == ENOENT || errno == EBADF)\n            ) {\n            file = fopen(filename, mode);\n        }\n    } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {\n        file = fopen(filename, mode);\n    }\n#  else\n    file = fopen(filename, mode);\n#  endif\n    return (file);\n}', 'void ERR_add_error_data(int num, ...)\n{\n    va_list args;\n    va_start(args, num);\n    ERR_add_error_vdata(num, args);\n    va_end(args);\n}', 'BIO *TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b)\n{\n    ctx->data = b;\n    return ctx->data;\n}', 'void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)\n{\n    if (!ctx)\n        return;\n    TS_VERIFY_CTX_cleanup(ctx);\n    OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']