int ASN1_object_size(int constructed, int length, int tag)
{
    int ret = 1;
    if (length < 0)
        return -1;
    if (tag >= 31) {
        while (tag > 0) {
            tag >>= 7;
            ret++;
        }
    }
    if (constructed == 2) {
        ret += 3;
    } else {
        ret++;
        if (length > 127) {
            int tmplen = length;
            while (tmplen > 0) {
                tmplen >>= 8;
                ret++;
            }
        }
    }
    if (ret >= INT_MAX - length)
        return -1;
    return ret + length;
}
['static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts,\n                           unsigned char *val, int len)\n{\n    unsigned char *tmpval;\n    ASN1_OCTET_STRING os;\n    int ret = 0;\n    if (len <= 0)\n        len = OCSP_DEFAULT_NONCE_LENGTH;\n    os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);\n    if (os.length < 0)\n        goto err;\n    os.data = OPENSSL_malloc(os.length);\n    if (os.data == NULL)\n        goto err;\n    tmpval = os.data;\n    ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);\n    if (val)\n        memcpy(tmpval, val, len);\n    else if (RAND_bytes(tmpval, len) <= 0)\n        goto err;\n    if (!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,\n                         &os, 0, X509V3_ADD_REPLACE))\n        goto err;\n    ret = 1;\n err:\n    OPENSSL_free(os.data);\n    return ret;\n}', 'int ASN1_object_size(int constructed, int length, int tag)\n{\n    int ret = 1;\n    if (length < 0)\n        return -1;\n    if (tag >= 31) {\n        while (tag > 0) {\n            tag >>= 7;\n            ret++;\n        }\n    }\n    if (constructed == 2) {\n        ret += 3;\n    } else {\n        ret++;\n        if (length > 127) {\n            int tmplen = length;\n            while (tmplen > 0) {\n                tmplen >>= 8;\n                ret++;\n            }\n        }\n    }\n    if (ret >= INT_MAX - length)\n        return -1;\n    return ret + length;\n}']