static int execute_cert_test(CT_TEST_FIXTURE fixture)
{
    int success = 0;
    X509 *cert = NULL, *issuer = NULL;
    STACK_OF(SCT) *scts = NULL;
    SCT *sct = NULL;
    char expected_sct_text[CT_TEST_MAX_FILE_SIZE];
    int sct_text_len = 0;
    unsigned char *tls_sct_list = NULL;
    size_t tls_sct_list_len = 0;
    CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
    if (fixture.sct_text_file != NULL) {
        sct_text_len = read_text_file(fixture.sct_dir, fixture.sct_text_file,
                                      expected_sct_text,
                                      CT_TEST_MAX_FILE_SIZE - 1);
        if (sct_text_len < 0) {
            fprintf(stderr, "Test data file not found: %s\n",
                fixture.sct_text_file);
            goto end;
        }
        expected_sct_text[sct_text_len] = '\0';
    }
    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
            ct_policy_ctx, fixture.ctlog_store);
    if (fixture.certificate_file != NULL) {
        int sct_extension_index;
        X509_EXTENSION *sct_extension = NULL;
        cert = load_pem_cert(fixture.certs_dir, fixture.certificate_file);
        if (cert == NULL) {
            fprintf(stderr, "Unable to load certificate: %s\n",
                fixture.certificate_file);
            goto end;
        }
        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);
        if (fixture.issuer_file != NULL) {
            issuer = load_pem_cert(fixture.certs_dir, fixture.issuer_file);
            if (issuer == NULL) {
                fprintf(stderr, "Unable to load issuer certificate: %s\n",
                        fixture.issuer_file);
                goto end;
            }
            CT_POLICY_EVAL_CTX_set1_issuer(ct_policy_ctx, issuer);
        }
        sct_extension_index =
                X509_get_ext_by_NID(cert, NID_ct_precert_scts, -1);
        sct_extension = X509_get_ext(cert, sct_extension_index);
        if (fixture.expected_sct_count > 0) {
            if (sct_extension == NULL) {
                fprintf(stderr, "SCT extension not found in: %s\n",
                    fixture.certificate_file);
                goto end;
            }
            if (fixture.sct_text_file
                && compare_extension_printout(sct_extension,
                                              expected_sct_text)) {
                    goto end;
            }
            if (fixture.test_validity) {
                int i;
                scts = X509V3_EXT_d2i(sct_extension);
                for (i = 0; i < sk_SCT_num(scts); ++i) {
                    SCT *sct_i = sk_SCT_value(scts, i);
                    if (!SCT_set_source(sct_i, SCT_SOURCE_X509V3_EXTENSION)) {
                        fprintf(stderr,
                                "Error setting SCT source to X509v3 extension\n");
                        goto end;
                    }
                }
                if (!assert_validity(fixture, scts, ct_policy_ctx))
                    goto end;
            }
        } else if (sct_extension != NULL) {
            fprintf(stderr,
                    "Expected no SCTs, but found SCT extension in: %s\n",
                    fixture.certificate_file);
            goto end;
        }
    }
    if (fixture.tls_sct_list != NULL) {
        const unsigned char *p = fixture.tls_sct_list;
        if (o2i_SCT_LIST(&scts, &p, fixture.tls_sct_list_len) == NULL) {
            fprintf(stderr, "Failed to decode SCTs from TLS format\n");
            goto end;
        }
        if (fixture.test_validity && cert != NULL) {
            if (!assert_validity(fixture, scts, ct_policy_ctx))
                goto end;
        }
        if (fixture.sct_text_file
            && compare_sct_list_printout(scts, expected_sct_text)) {
                goto end;
        }
        tls_sct_list_len = i2o_SCT_LIST(scts, &tls_sct_list);
        if (tls_sct_list_len != fixture.tls_sct_list_len ||
            memcmp(fixture.tls_sct_list, tls_sct_list, tls_sct_list_len) != 0) {
            fprintf(stderr,
                    "Failed to encode SCTs into TLS format correctly\n");
            goto end;
        }
    }
    success = 1;
end:
    X509_free(cert);
    X509_free(issuer);
    SCT_LIST_free(scts);
    SCT_free(sct);
    CT_POLICY_EVAL_CTX_free(ct_policy_ctx);
    OPENSSL_free(tls_sct_list);
    return success;
}
['static int execute_cert_test(CT_TEST_FIXTURE fixture)\n{\n    int success = 0;\n    X509 *cert = NULL, *issuer = NULL;\n    STACK_OF(SCT) *scts = NULL;\n    SCT *sct = NULL;\n    char expected_sct_text[CT_TEST_MAX_FILE_SIZE];\n    int sct_text_len = 0;\n    unsigned char *tls_sct_list = NULL;\n    size_t tls_sct_list_len = 0;\n    CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();\n    if (fixture.sct_text_file != NULL) {\n        sct_text_len = read_text_file(fixture.sct_dir, fixture.sct_text_file,\n                                      expected_sct_text,\n                                      CT_TEST_MAX_FILE_SIZE - 1);\n        if (sct_text_len < 0) {\n            fprintf(stderr, "Test data file not found: %s\\n",\n                fixture.sct_text_file);\n            goto end;\n        }\n        expected_sct_text[sct_text_len] = \'\\0\';\n    }\n    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(\n            ct_policy_ctx, fixture.ctlog_store);\n    if (fixture.certificate_file != NULL) {\n        int sct_extension_index;\n        X509_EXTENSION *sct_extension = NULL;\n        cert = load_pem_cert(fixture.certs_dir, fixture.certificate_file);\n        if (cert == NULL) {\n            fprintf(stderr, "Unable to load certificate: %s\\n",\n                fixture.certificate_file);\n            goto end;\n        }\n        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);\n        if (fixture.issuer_file != NULL) {\n            issuer = load_pem_cert(fixture.certs_dir, fixture.issuer_file);\n            if (issuer == NULL) {\n                fprintf(stderr, "Unable to load issuer certificate: %s\\n",\n                        fixture.issuer_file);\n                goto end;\n            }\n            CT_POLICY_EVAL_CTX_set1_issuer(ct_policy_ctx, issuer);\n        }\n        sct_extension_index =\n                X509_get_ext_by_NID(cert, NID_ct_precert_scts, -1);\n        sct_extension = X509_get_ext(cert, sct_extension_index);\n        if (fixture.expected_sct_count > 0) {\n            if (sct_extension == NULL) {\n                fprintf(stderr, "SCT extension not found in: %s\\n",\n                    fixture.certificate_file);\n                goto end;\n            }\n            if (fixture.sct_text_file\n                && compare_extension_printout(sct_extension,\n                                              expected_sct_text)) {\n                    goto end;\n            }\n            if (fixture.test_validity) {\n                int i;\n                scts = X509V3_EXT_d2i(sct_extension);\n                for (i = 0; i < sk_SCT_num(scts); ++i) {\n                    SCT *sct_i = sk_SCT_value(scts, i);\n                    if (!SCT_set_source(sct_i, SCT_SOURCE_X509V3_EXTENSION)) {\n                        fprintf(stderr,\n                                "Error setting SCT source to X509v3 extension\\n");\n                        goto end;\n                    }\n                }\n                if (!assert_validity(fixture, scts, ct_policy_ctx))\n                    goto end;\n            }\n        } else if (sct_extension != NULL) {\n            fprintf(stderr,\n                    "Expected no SCTs, but found SCT extension in: %s\\n",\n                    fixture.certificate_file);\n            goto end;\n        }\n    }\n    if (fixture.tls_sct_list != NULL) {\n        const unsigned char *p = fixture.tls_sct_list;\n        if (o2i_SCT_LIST(&scts, &p, fixture.tls_sct_list_len) == NULL) {\n            fprintf(stderr, "Failed to decode SCTs from TLS format\\n");\n            goto end;\n        }\n        if (fixture.test_validity && cert != NULL) {\n            if (!assert_validity(fixture, scts, ct_policy_ctx))\n                goto end;\n        }\n        if (fixture.sct_text_file\n            && compare_sct_list_printout(scts, expected_sct_text)) {\n                goto end;\n        }\n        tls_sct_list_len = i2o_SCT_LIST(scts, &tls_sct_list);\n        if (tls_sct_list_len != fixture.tls_sct_list_len ||\n            memcmp(fixture.tls_sct_list, tls_sct_list, tls_sct_list_len) != 0) {\n            fprintf(stderr,\n                    "Failed to encode SCTs into TLS format correctly\\n");\n            goto end;\n        }\n    }\n    success = 1;\nend:\n    X509_free(cert);\n    X509_free(issuer);\n    SCT_LIST_free(scts);\n    SCT_free(sct);\n    CT_POLICY_EVAL_CTX_free(ct_policy_ctx);\n    OPENSSL_free(tls_sct_list);\n    return success;\n}', 'CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void)\n{\n    CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));\n    if (ctx == NULL) {\n        CTerr(CT_F_CT_POLICY_EVAL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\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}', 'void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx,\n                                               CTLOG_STORE *log_store)\n{\n    ctx->log_store = log_store;\n}']