int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
{
    char *v;
    int gmt = 0;
    int i;
    int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;
    char *f = NULL;
    int f_len = 0;
    i = tm->length;
    v = (char *)tm->data;
    if (i < 12)
        goto err;
    if (v[i - 1] == 'Z')
        gmt = 1;
    for (i = 0; i < 12; i++)
        if ((v[i] > '9') || (v[i] < '0'))
            goto err;
    y = (v[0] - '0') * 1000 + (v[1] - '0') * 100
        + (v[2] - '0') * 10 + (v[3] - '0');
    M = (v[4] - '0') * 10 + (v[5] - '0');
    if ((M > 12) || (M < 1))
        goto err;
    d = (v[6] - '0') * 10 + (v[7] - '0');
    h = (v[8] - '0') * 10 + (v[9] - '0');
    m = (v[10] - '0') * 10 + (v[11] - '0');
    if (tm->length >= 14 &&
        (v[12] >= '0') && (v[12] <= '9') &&
        (v[13] >= '0') && (v[13] <= '9')) {
        s = (v[12] - '0') * 10 + (v[13] - '0');
        if (tm->length >= 15 && v[14] == '.') {
            int l = tm->length;
            f = &v[14];
            f_len = 1;
            while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
                ++f_len;
        }
    }
    if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",
                   _asn1_mon[M - 1], d, h, m, s, f_len, f, y,
                   (gmt) ? " GMT" : "") <= 0)
        return (0);
    else
        return (1);
 err:
    BIO_write(bp, "Bad time value", 14);
    return (0);
}
['int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,\n                  unsigned long cflag)\n{\n    long l;\n    int ret = 0, i;\n    char *m = NULL, mlch = \' \';\n    int nmindent = 0;\n    ASN1_INTEGER *bs;\n    EVP_PKEY *pkey = NULL;\n    const char *neg;\n    if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {\n        mlch = \'\\n\';\n        nmindent = 12;\n    }\n    if (nmflags == X509_FLAG_COMPAT)\n        nmindent = 16;\n    if (!(cflag & X509_FLAG_NO_HEADER)) {\n        if (BIO_write(bp, "Certificate:\\n", 13) <= 0)\n            goto err;\n        if (BIO_write(bp, "    Data:\\n", 10) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_VERSION)) {\n        l = X509_get_version(x);\n        if (BIO_printf(bp, "%8sVersion: %lu (0x%lx)\\n", "", l + 1, l) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_SERIAL)) {\n        if (BIO_write(bp, "        Serial Number:", 22) <= 0)\n            goto err;\n        bs = X509_get_serialNumber(x);\n        if (bs->length <= (int)sizeof(long)) {\n                ERR_set_mark();\n                l = ASN1_INTEGER_get(bs);\n                ERR_pop_to_mark();\n        } else {\n            l = -1;\n        }\n        if (l != -1) {\n            if (bs->type == V_ASN1_NEG_INTEGER) {\n                l = -l;\n                neg = "-";\n            } else\n                neg = "";\n            if (BIO_printf(bp, " %s%lu (%s0x%lx)\\n", neg, l, neg, l) <= 0)\n                goto err;\n        } else {\n            neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";\n            if (BIO_printf(bp, "\\n%12s%s", "", neg) <= 0)\n                goto err;\n            for (i = 0; i < bs->length; i++) {\n                if (BIO_printf(bp, "%02x%c", bs->data[i],\n                               ((i + 1 == bs->length) ? \'\\n\' : \':\')) <= 0)\n                    goto err;\n            }\n        }\n    }\n    if (!(cflag & X509_FLAG_NO_SIGNAME)) {\n        X509_ALGOR *tsig_alg = X509_get0_tbs_sigalg(x);\n        if (X509_signature_print(bp, tsig_alg, NULL) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_ISSUER)) {\n        if (BIO_printf(bp, "        Issuer:%c", mlch) <= 0)\n            goto err;\n        if (X509_NAME_print_ex(bp, X509_get_issuer_name(x), nmindent, nmflags)\n            < 0)\n            goto err;\n        if (BIO_write(bp, "\\n", 1) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_VALIDITY)) {\n        if (BIO_write(bp, "        Validity\\n", 17) <= 0)\n            goto err;\n        if (BIO_write(bp, "            Not Before: ", 24) <= 0)\n            goto err;\n        if (!ASN1_TIME_print(bp, X509_get_notBefore(x)))\n            goto err;\n        if (BIO_write(bp, "\\n            Not After : ", 25) <= 0)\n            goto err;\n        if (!ASN1_TIME_print(bp, X509_get_notAfter(x)))\n            goto err;\n        if (BIO_write(bp, "\\n", 1) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_SUBJECT)) {\n        if (BIO_printf(bp, "        Subject:%c", mlch) <= 0)\n            goto err;\n        if (X509_NAME_print_ex\n            (bp, X509_get_subject_name(x), nmindent, nmflags) < 0)\n            goto err;\n        if (BIO_write(bp, "\\n", 1) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_PUBKEY)) {\n        X509_PUBKEY *xpkey = X509_get_X509_PUBKEY(x);\n        ASN1_OBJECT *xpoid;\n        X509_PUBKEY_get0_param(&xpoid, NULL, NULL, NULL, xpkey);\n        if (BIO_write(bp, "        Subject Public Key Info:\\n", 33) <= 0)\n            goto err;\n        if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)\n            goto err;\n        if (i2a_ASN1_OBJECT(bp, xpoid) <= 0)\n            goto err;\n        if (BIO_puts(bp, "\\n") <= 0)\n            goto err;\n        pkey = X509_get_pubkey(x);\n        if (pkey == NULL) {\n            BIO_printf(bp, "%12sUnable to load Public Key\\n", "");\n            ERR_print_errors(bp);\n        } else {\n            EVP_PKEY_print_public(bp, pkey, 16, NULL);\n            EVP_PKEY_free(pkey);\n        }\n    }\n    if (!(cflag & X509_FLAG_NO_IDS)) {\n        ASN1_BIT_STRING *iuid, *suid;\n        X509_get0_uids(&iuid, &suid, x);\n        if (iuid != NULL) {\n            if (BIO_printf(bp, "%8sIssuer Unique ID: ", "") <= 0)\n                goto err;\n            if (!X509_signature_dump(bp, iuid, 12))\n                goto err;\n        }\n        if (suid != NULL) {\n            if (BIO_printf(bp, "%8sSubject Unique ID: ", "") <= 0)\n                goto err;\n            if (!X509_signature_dump(bp, suid, 12))\n                goto err;\n        }\n    }\n    if (!(cflag & X509_FLAG_NO_EXTENSIONS))\n        X509V3_extensions_print(bp, "X509v3 extensions",\n                                X509_get0_extensions(x), cflag, 8);\n    if (!(cflag & X509_FLAG_NO_SIGDUMP)) {\n        X509_ALGOR *sig_alg;\n        ASN1_BIT_STRING *sig;\n        X509_get0_signature(&sig, &sig_alg, x);\n        if (X509_signature_print(bp, sig_alg, sig) <= 0)\n            goto err;\n    }\n    if (!(cflag & X509_FLAG_NO_AUX)) {\n        if (!X509_aux_print(bp, x, 0))\n            goto err;\n    }\n    ret = 1;\n err:\n    OPENSSL_free(m);\n    return (ret);\n}', 'long X509_get_version(X509 *x)\n{\n    return ASN1_INTEGER_get(x->cert_info.version);\n}', 'long ASN1_INTEGER_get(const ASN1_INTEGER *a)\n{\n    int i;\n    int64_t r;\n    if (a == NULL)\n        return 0;\n    i = ASN1_INTEGER_get_int64(&r, a);\n    if (i == 0)\n        return -1;\n    if (r > LONG_MAX || r < LONG_MIN)\n        return -1;\n    return (long)r;\n}', 'int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm)\n{\n    if (tm->type == V_ASN1_UTCTIME)\n        return ASN1_UTCTIME_print(bp, tm);\n    if (tm->type == V_ASN1_GENERALIZEDTIME)\n        return ASN1_GENERALIZEDTIME_print(bp, tm);\n    BIO_write(bp, "Bad time value", 14);\n    return (0);\n}', 'int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)\n{\n    char *v;\n    int gmt = 0;\n    int i;\n    int y = 0, M = 0, d = 0, h = 0, m = 0, s = 0;\n    char *f = NULL;\n    int f_len = 0;\n    i = tm->length;\n    v = (char *)tm->data;\n    if (i < 12)\n        goto err;\n    if (v[i - 1] == \'Z\')\n        gmt = 1;\n    for (i = 0; i < 12; i++)\n        if ((v[i] > \'9\') || (v[i] < \'0\'))\n            goto err;\n    y = (v[0] - \'0\') * 1000 + (v[1] - \'0\') * 100\n        + (v[2] - \'0\') * 10 + (v[3] - \'0\');\n    M = (v[4] - \'0\') * 10 + (v[5] - \'0\');\n    if ((M > 12) || (M < 1))\n        goto err;\n    d = (v[6] - \'0\') * 10 + (v[7] - \'0\');\n    h = (v[8] - \'0\') * 10 + (v[9] - \'0\');\n    m = (v[10] - \'0\') * 10 + (v[11] - \'0\');\n    if (tm->length >= 14 &&\n        (v[12] >= \'0\') && (v[12] <= \'9\') &&\n        (v[13] >= \'0\') && (v[13] <= \'9\')) {\n        s = (v[12] - \'0\') * 10 + (v[13] - \'0\');\n        if (tm->length >= 15 && v[14] == \'.\') {\n            int l = tm->length;\n            f = &v[14];\n            f_len = 1;\n            while (14 + f_len < l && f[f_len] >= \'0\' && f[f_len] <= \'9\')\n                ++f_len;\n        }\n    }\n    if (BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s",\n                   _asn1_mon[M - 1], d, h, m, s, f_len, f, y,\n                   (gmt) ? " GMT" : "") <= 0)\n        return (0);\n    else\n        return (1);\n err:\n    BIO_write(bp, "Bad time value", 14);\n    return (0);\n}']