PR_fprintf(outFile, "%s\n", NS_CERTREQ_TRAILER);
PR_fprintf(outFile, "\n%s\n", NS_CERTREQ_TRAILER);
CertReq(SECKEYPrivateKey *privk, SECKEYPublicKey *pubk, KeyType keyType,	CERTName *subject, char *phone, int ascii, PRFileDesc *outFile){    CERTSubjectPublicKeyInfo *spki;    CERTCertificateRequest *cr;    SECItem *encoding;    SECItem result;    SECStatus rv;    PRArenaPool *arena;    PRInt32 numBytes;    /* Create info about public key */    spki = SECKEY_CreateSubjectPublicKeyInfo(pubk);    if (!spki) {	SECU_PrintError(progName, "unable to create subject public key");	return SECFailure;    }    /* Generate certificate request */    cr = CERT_CreateCertificateRequest(subject, spki, 0);    if (!cr) {	SECU_PrintError(progName, "unable to make certificate request");	return SECFailure;    }    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);    if ( !arena ) {	SECU_PrintError(progName, "out of memory");	return SECFailure;    }        /* Der encode the request */    encoding = SEC_ASN1EncodeItem(arena, NULL, cr,		  SEC_ASN1_GET(CERT_CertificateRequestTemplate));    if (encoding == NULL) {	SECU_PrintError(progName, "der encoding of request failed");	return SECFailure;    }    /* Sign the request */    switch (keyType) {    case rsaKey:	rv = SEC_DerSignData(arena, &result, encoding->data, encoding->len, 	                     privk, SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION);	break;    case dsaKey:	rv = SEC_DerSignData(arena, &result, encoding->data, encoding->len, 	                 privk, SEC_OID_ANSIX9_DSA_SIGNATURE_WITH_SHA1_DIGEST);	break;    default:	SECU_PrintError(progName, "Must use rsa or dsa key type");	return SECFailure;    }    if (rv) {	SECU_PrintError(progName, "signing of data failed");	return SECFailure;    }    /* Encode request in specified format */    if (ascii) {	char *obuf;	char *name, *email, *org, *state, *country;	SECItem *it;	int total;	it = &result;	obuf = BTOA_ConvertItemToAscii(it);	total = PL_strlen(obuf);	name = CERT_GetCommonName(subject);	if (!name) {	    fprintf(stderr, "You must specify a common name\n");	    return SECFailure;	}	if (!phone)	    phone = strdup("(not specified)");	email = CERT_GetCertEmailAddress(subject);	if (!email)	    email = strdup("(not specified)");	org = CERT_GetOrgName(subject);	if (!org)	    org = strdup("(not specified)");	state = CERT_GetStateName(subject);	if (!state)	    state = strdup("(not specified)");	country = CERT_GetCountryName(subject);	if (!country)	    country = strdup("(not specified)");	PR_fprintf(outFile, 	           "\nCertificate request generated by Netscape certutil\n");	PR_fprintf(outFile, "Phone: %s\n\n", phone);	PR_fprintf(outFile, "Common Name: %s\n", name);	PR_fprintf(outFile, "Email: %s\n", email);	PR_fprintf(outFile, "Organization: %s\n", org);	PR_fprintf(outFile, "State: %s\n", state);	PR_fprintf(outFile, "Country: %s\n\n", country);	PR_fprintf(outFile, "%s\n", NS_CERTREQ_HEADER);	numBytes = PR_Write(outFile, obuf, total);	if (numBytes != total) {	    SECU_PrintSystemError(progName, "write error");	    return SECFailure;	}	PR_fprintf(outFile, "%s\n", NS_CERTREQ_TRAILER);    } else {	numBytes = PR_Write(outFile, result.data, result.len);	if (numBytes != (int)result.len) {	    SECU_PrintSystemError(progName, "write error");	    return SECFailure;	}    }    return SECSuccess;}