int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)
{
    ASN1_TIME t;
    struct tm tm;
    int rv = 0;
    t.length = strlen(str);
    t.data = (unsigned char *)str;
    t.flags = ASN1_STRING_FLAG_X509_TIME;
    t.type = V_ASN1_UTCTIME;
    if (!ASN1_TIME_check(&t)) {
        t.type = V_ASN1_GENERALIZEDTIME;
        if (!ASN1_TIME_check(&t))
            goto out;
    }
    if (s != NULL && t.type == V_ASN1_GENERALIZEDTIME) {
        if (!asn1_time_to_tm(&tm, &t))
            goto out;
        if (is_utc(tm.tm_year)) {
            t.length -= 2;
            t.data = OPENSSL_zalloc(t.length + 1);
            if (t.data == NULL)
                goto out;
            memcpy(t.data, str + 2, t.length);
            t.type = V_ASN1_UTCTIME;
        }
    }
    if (s == NULL || ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
        rv = 1;
    if (t.data != (unsigned char *)str)
        OPENSSL_free(t.data);
out:
    return rv;
}
['static int sign(X509 *x, EVP_PKEY *pkey, EVP_PKEY *fkey, int days, int clrext,\n                const EVP_MD *digest, CONF *conf, const char *section,\n                int preserve_dates)\n{\n    if (!X509_set_issuer_name(x, X509_get_subject_name(x)))\n        goto err;\n    if (!preserve_dates && !set_cert_times(x, NULL, NULL, days))\n        goto err;\n    if (fkey == NULL && !X509_set_pubkey(x, pkey))\n        goto err;\n    if (clrext) {\n        while (X509_get_ext_count(x) > 0)\n            X509_delete_ext(x, 0);\n    }\n    if (conf != NULL) {\n        X509V3_CTX ctx;\n        X509_set_version(x, 2);\n        X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);\n        X509V3_set_nconf(&ctx, conf);\n        if (!X509V3_EXT_add_nconf(conf, &ctx, section, x))\n            goto err;\n    }\n    if (!X509_sign(x, pkey, digest))\n        goto err;\n    return 1;\n err:\n    ERR_print_errors(bio_err);\n    return 0;\n}', 'int X509_set_issuer_name(X509 *x, X509_NAME *name)\n{\n    if (x == NULL)\n        return 0;\n    return X509_NAME_set(&x->cert_info.issuer, name);\n}', 'int X509_NAME_set(X509_NAME **xn, const X509_NAME *name)\n{\n    X509_NAME *name_copy;\n    if (*xn == name)\n        return *xn != NULL;\n    if ((name_copy = X509_NAME_dup(name)) == NULL)\n        return 0;\n    X509_NAME_free(*xn);\n    *xn = name_copy;\n    return 1;\n}', 'IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)', 'void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)\n{\n    unsigned char *b = NULL;\n    const unsigned char *p;\n    long i;\n    void *ret;\n    if (x == NULL)\n        return NULL;\n    i = ASN1_item_i2d(x, &b, it);\n    if (b == NULL) {\n        ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    p = b;\n    ret = ASN1_item_d2i(NULL, &p, i, it);\n    OPENSSL_free(b);\n    return ret;\n}', 'int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n{\n    return asn1_item_flags_i2d(val, out, it, 0);\n}', 'static int asn1_item_flags_i2d(const ASN1_VALUE *val, unsigned char **out,\n                               const ASN1_ITEM *it, int flags)\n{\n    if (out && !*out) {\n        unsigned char *p, *buf;\n        int len;\n        len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n        if (len <= 0)\n            return len;\n        if ((buf = OPENSSL_malloc(len)) == NULL) {\n            ASN1err(ASN1_F_ASN1_ITEM_FLAGS_I2D, ERR_R_MALLOC_FAILURE);\n            return -1;\n        }\n        p = buf;\n        ASN1_item_ex_i2d(&val, &p, it, -1, flags);\n        *out = buf;\n        return len;\n    }\n    return ASN1_item_ex_i2d(&val, out, it, -1, flags);\n}', 'int set_cert_times(X509 *x, const char *startdate, const char *enddate,\n                   int days)\n{\n    if (startdate == NULL || strcmp(startdate, "today") == 0) {\n        if (X509_gmtime_adj(X509_getm_notBefore(x), 0) == NULL)\n            return 0;\n    } else {\n        if (!ASN1_TIME_set_string_X509(X509_getm_notBefore(x), startdate))\n            return 0;\n    }\n    if (enddate == NULL) {\n        if (X509_time_adj_ex(X509_getm_notAfter(x), days, 0, NULL)\n            == NULL)\n            return 0;\n    } else if (!ASN1_TIME_set_string_X509(X509_getm_notAfter(x), enddate)) {\n        return 0;\n    }\n    return 1;\n}', 'int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)\n{\n    ASN1_TIME t;\n    struct tm tm;\n    int rv = 0;\n    t.length = strlen(str);\n    t.data = (unsigned char *)str;\n    t.flags = ASN1_STRING_FLAG_X509_TIME;\n    t.type = V_ASN1_UTCTIME;\n    if (!ASN1_TIME_check(&t)) {\n        t.type = V_ASN1_GENERALIZEDTIME;\n        if (!ASN1_TIME_check(&t))\n            goto out;\n    }\n    if (s != NULL && t.type == V_ASN1_GENERALIZEDTIME) {\n        if (!asn1_time_to_tm(&tm, &t))\n            goto out;\n        if (is_utc(tm.tm_year)) {\n            t.length -= 2;\n            t.data = OPENSSL_zalloc(t.length + 1);\n            if (t.data == NULL)\n                goto out;\n            memcpy(t.data, str + 2, t.length);\n            t.type = V_ASN1_UTCTIME;\n        }\n    }\n    if (s == NULL || ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))\n        rv = 1;\n    if (t.data != (unsigned char *)str)\n        OPENSSL_free(t.data);\nout:\n    return rv;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\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    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']