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 (!TEST_int_ge(sct_text_len, 0))
            goto end;
        expected_sct_text[sct_text_len] = '\0';
    }
    CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(
            ct_policy_ctx, fixture->ctlog_store);
    CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);
    if (fixture->certificate_file != NULL) {
        int sct_extension_index;
        int i;
        X509_EXTENSION *sct_extension = NULL;
        if (!TEST_ptr(cert = load_pem_cert(fixture->certs_dir,
                                           fixture->certificate_file)))
            goto end;
        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);
        if (fixture->issuer_file != NULL) {
            if (!TEST_ptr(issuer = load_pem_cert(fixture->certs_dir,
                                                 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 (!TEST_ptr(sct_extension))
                goto end;
            if (fixture->sct_text_file
                && !compare_extension_printout(sct_extension,
                                               expected_sct_text))
                    goto end;
            scts = X509V3_EXT_d2i(sct_extension);
            for (i = 0; i < sk_SCT_num(scts); ++i) {
                SCT *sct_i = sk_SCT_value(scts, i);
                if (!TEST_int_eq(SCT_get_source(sct_i),
                                 SCT_SOURCE_X509V3_EXTENSION)) {
                    goto end;
                }
            }
            if (fixture->test_validity) {
                if (!assert_validity(fixture, scts, ct_policy_ctx))
                    goto end;
            }
        } else if (!TEST_ptr_null(sct_extension)) {
            goto end;
        }
    }
    if (fixture->tls_sct_list != NULL) {
        const unsigned char *p = fixture->tls_sct_list;
        if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))
            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 (!TEST_mem_eq(fixture->tls_sct_list, fixture->tls_sct_list_len,
                         tls_sct_list, tls_sct_list_len))
            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 (!TEST_int_ge(sct_text_len, 0))\n            goto end;\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    CT_POLICY_EVAL_CTX_set_time(ct_policy_ctx, fixture->epoch_time_in_ms);\n    if (fixture->certificate_file != NULL) {\n        int sct_extension_index;\n        int i;\n        X509_EXTENSION *sct_extension = NULL;\n        if (!TEST_ptr(cert = load_pem_cert(fixture->certs_dir,\n                                           fixture->certificate_file)))\n            goto end;\n        CT_POLICY_EVAL_CTX_set1_cert(ct_policy_ctx, cert);\n        if (fixture->issuer_file != NULL) {\n            if (!TEST_ptr(issuer = load_pem_cert(fixture->certs_dir,\n                                                 fixture->issuer_file)))\n                goto end;\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 (!TEST_ptr(sct_extension))\n                goto end;\n            if (fixture->sct_text_file\n                && !compare_extension_printout(sct_extension,\n                                               expected_sct_text))\n                    goto end;\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 (!TEST_int_eq(SCT_get_source(sct_i),\n                                 SCT_SOURCE_X509V3_EXTENSION)) {\n                    goto end;\n                }\n            }\n            if (fixture->test_validity) {\n                if (!assert_validity(fixture, scts, ct_policy_ctx))\n                    goto end;\n            }\n        } else if (!TEST_ptr_null(sct_extension)) {\n            goto end;\n        }\n    }\n    if (fixture->tls_sct_list != NULL) {\n        const unsigned char *p = fixture->tls_sct_list;\n        if (!TEST_ptr(o2i_SCT_LIST(&scts, &p, fixture->tls_sct_list_len)))\n            goto end;\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 (!TEST_mem_eq(fixture->tls_sct_list, fixture->tls_sct_list_len,\n                         tls_sct_list, tls_sct_list_len))\n            goto end;\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}", '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}', 'void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms)\n{\n    ctx->epoch_time_in_ms = time_in_ms;\n}', 'STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp,\n                            size_t len)\n{\n    STACK_OF(SCT) *sk = NULL;\n    size_t list_len, sct_len;\n    if (len < 2 || len > MAX_SCT_LIST_SIZE) {\n        CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n        return NULL;\n    }\n    n2s(*pp, list_len);\n    if (list_len != len - 2) {\n        CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n        return NULL;\n    }\n    if (a == NULL || *a == NULL) {\n        sk = sk_SCT_new_null();\n        if (sk == NULL)\n            return NULL;\n    } else {\n        SCT *sct;\n        sk = *a;\n        while ((sct = sk_SCT_pop(sk)) != NULL)\n            SCT_free(sct);\n    }\n    while (list_len > 0) {\n        SCT *sct;\n        if (list_len < 2) {\n            CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n            goto err;\n        }\n        n2s(*pp, sct_len);\n        list_len -= 2;\n        if (sct_len == 0 || sct_len > list_len) {\n            CTerr(CT_F_O2I_SCT_LIST, CT_R_SCT_LIST_INVALID);\n            goto err;\n        }\n        list_len -= sct_len;\n        if ((sct = o2i_SCT(NULL, pp, sct_len)) == NULL)\n            goto err;\n        if (!sk_SCT_push(sk, sct)) {\n            SCT_free(sct);\n            goto err;\n        }\n    }\n    if (a != NULL && *a == NULL)\n        *a = sk;\n    return sk;\n err:\n    if (a == NULL || *a == NULL)\n        SCT_LIST_free(sk);\n    return NULL;\n}', 'void *OPENSSL_sk_pop(OPENSSL_STACK *st)\n{\n    if (st == NULL || st->num == 0)\n        return NULL;\n    return internal_delete(st, st->num - 1);\n}', 'static ossl_inline void *internal_delete(OPENSSL_STACK *st, int loc)\n{\n    const void *ret = st->data[loc];\n    if (loc != st->num - 1)\n         memmove(&st->data[loc], &st->data[loc + 1],\n                 sizeof(st->data[0]) * (st->num - loc - 1));\n    st->num--;\n    return (void *)ret;\n}']