static int ct_base64_decode(const char *in, unsigned char **out)
{
    size_t inlen = strlen(in);
    int outlen;
    unsigned char *outbuf = NULL;
    if (inlen == 0) {
        *out = NULL;
        return 0;
    }
    outlen = (inlen / 4) * 3;
    outbuf = OPENSSL_malloc(outlen);
    if (outbuf == NULL) {
        CTerr(CT_F_CT_BASE64_DECODE, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);
    if (outlen < 0) {
        CTerr(CT_F_CT_BASE64_DECODE, CT_R_BASE64_DECODE_ERROR);
        goto err;
    }
    while (in[--inlen] == '=') {
        --outlen;
    }
    *out = outbuf;
    return outlen;
err:
    OPENSSL_free(outbuf);
    return -1;
}
['static int test_encode_tls_sct()\n{\n    const char log_id[] = "3xwuwRUAlFJHqWFoMl3cXHlZ6PfG04j8AC4LvT9012Q=";\n    const uint64_t timestamp = 1;\n    const char extensions[] = "";\n    const char signature[] = "BAMARzBAMiBIL2dRrzXbplQ2vh/WZA89v5pBQpSVkkUwKI+j5"\n            "eI+BgIhAOTtwNs6xXKx4vXoq2poBlOYfc9BAn3+/6EFUZ2J7b8I";\n    SCT *sct = NULL;\n    SETUP_CT_TEST_FIXTURE();\n    fixture.sct_list = sk_SCT_new_null();\n    sct = SCT_new_from_base64(SCT_VERSION_V1, log_id,\n                              CT_LOG_ENTRY_TYPE_X509, timestamp,\n                              extensions, signature);\n    if (sct == NULL) {\n        tear_down(fixture);\n        fprintf(stderr, "Failed to create SCT from base64-encoded test data\\n");\n        return 0;\n    }\n    sk_SCT_push(fixture.sct_list, sct);\n    fixture.sct_dir = ct_dir;\n    fixture.sct_text_file = "tls1.sct";\n    EXECUTE_CT_TEST();\n}', 'SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,\n                         ct_log_entry_type_t entry_type, uint64_t timestamp,\n                         const char *extensions_base64,\n                         const char *signature_base64)\n{\n    SCT *sct = SCT_new();\n    unsigned char *dec = NULL;\n    const unsigned char* p = NULL;\n    int declen;\n    if (sct == NULL) {\n        CTerr(CT_F_SCT_NEW_FROM_BASE64, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    if (!SCT_set_version(sct, version)) {\n        CTerr(CT_F_SCT_NEW_FROM_BASE64, CT_R_SCT_UNSUPPORTED_VERSION);\n        goto err;\n    }\n    declen = ct_base64_decode(logid_base64, &dec);\n    if (declen < 0) {\n        CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n        goto err;\n    }\n    if (!SCT_set0_log_id(sct, dec, declen))\n        goto err;\n    dec = NULL;\n    declen = ct_base64_decode(extensions_base64, &dec);\n    if (declen < 0) {\n        CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n        goto err;\n    }\n    SCT_set0_extensions(sct, dec, declen);\n    dec = NULL;\n    declen = ct_base64_decode(signature_base64, &dec);\n    if (declen < 0) {\n        CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n        goto err;\n    }\n    p = dec;\n    if (o2i_SCT_signature(sct, &p, declen) <= 0)\n        goto err;\n    OPENSSL_free(dec);\n    dec = NULL;\n    SCT_set_timestamp(sct, timestamp);\n    if (!SCT_set_log_entry_type(sct, entry_type))\n        goto err;\n    return sct;\n err:\n    OPENSSL_free(dec);\n    SCT_free(sct);\n    return NULL;\n}', "static int ct_base64_decode(const char *in, unsigned char **out)\n{\n    size_t inlen = strlen(in);\n    int outlen;\n    unsigned char *outbuf = NULL;\n    if (inlen == 0) {\n        *out = NULL;\n        return 0;\n    }\n    outlen = (inlen / 4) * 3;\n    outbuf = OPENSSL_malloc(outlen);\n    if (outbuf == NULL) {\n        CTerr(CT_F_CT_BASE64_DECODE, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);\n    if (outlen < 0) {\n        CTerr(CT_F_CT_BASE64_DECODE, CT_R_BASE64_DECODE_ERROR);\n        goto err;\n    }\n    while (in[--inlen] == '=') {\n        --outlen;\n    }\n    *out = outbuf;\n    return outlen;\nerr:\n    OPENSSL_free(outbuf);\n    return -1;\n}"]