return 6;
return 5;
CreateCertRequest (CRMFCertRequest **inCertReq, SECKEYPrivateKey **privKey,		   SECKEYPublicKey **pubKey){    long serialNumber;    long version = 3;    char *issuerStr = PORT_Strdup ("CN=Javi's CA Shack, O=Information Systems");    char *subjectStr = PORT_Strdup ("CN=Javi's CA Shack ID, O=Engineering, "				    "C=US");    CRMFCertRequest *certReq;    SECAlgorithmID * algID;    CERTName *issuer, *subject;    CRMFValidityCreationInfo validity;    CERTSubjectPublicKeyInfo *spki;    SECStatus rv;    SECOidTag tag, tag2;    SECItem issuerUID, subjectUID;    CRMFCertExtCreationInfo *extInfo;    CRMFEncryptedKey  *encKey;    CERTCertificate *caCert;    CRMFPKIArchiveOptions *pkiArchOpt;      *inCertReq = NULL;    certReq = CRMF_CreateCertRequest(0x0ff02345);    if (certReq == NULL) {        printf ("Could not initialize a certificate request.\n");	return 1;    }    rv = CRMF_CertRequestSetTemplateField (certReq, crmfVersion, (void*)(&version));    if (rv != SECSuccess) {        printf("Could not add the version number to the "	       "Certificate Request.\n");	CRMF_DestroyCertRequest(certReq);	return 2;    }    if (get_serial_number(&serialNumber) != SECSuccess) {        printf ("Could not generate a serial number for cert request.\n");	CRMF_DestroyCertRequest(certReq);	return 3;    }    rv = CRMF_CertRequestSetTemplateField (certReq, crmfSerialNumber, 				      (void*)(&serialNumber));    if (rv != SECSuccess) {        printf ("Could not add serial number to certificate template\n.");	CRMF_DestroyCertRequest(certReq);	return 4;    }        issuer = CERT_AsciiToName(issuerStr);    if (issuer == NULL) {        printf ("Could not create CERTName structure from %s.\n", issuerStr);	CRMF_DestroyCertRequest(certReq);	return 5;    }    rv = CRMF_CertRequestSetTemplateField (certReq, crmfIssuer, (void*) issuer);    PORT_Free(issuerStr);    CERT_DestroyName(issuer);    if (rv != SECSuccess) {        printf ("Could not add issuer to cert template\n");	CRMF_DestroyCertRequest(certReq);	return 6;    }    subject = CERT_AsciiToName(subjectStr);    if (subject == NULL) {        printf ("Could not create CERTName structure from %s.\n", subjectStr);	CRMF_DestroyCertRequest(certReq);	return 7;    }    PORT_Free(subjectStr);    rv = CRMF_CertRequestSetTemplateField (certReq, crmfSubject, (void*)subject);    if (rv != SECSuccess) {        printf ("Could not add subject to cert template\n");	CRMF_DestroyCertRequest(certReq);	return 8;    }    CERT_DestroyName(subject);    algID =    SEC_PKCS5CreateAlgorithmID (SEC_OID_PKCS5_PBE_WITH_SHA1_AND_DES_CBC,			       NULL, 1);    if (algID == NULL) {        printf ("Couldn't create algorithm ID\n");	CRMF_DestroyCertRequest(certReq);	return 9;    }    rv = CRMF_CertRequestSetTemplateField(certReq, crmfSigningAlg, (void*)algID);    SECOID_DestroyAlgorithmID(algID, PR_TRUE);    if (rv != SECSuccess) {        printf ("Could not add the signing algorithm to the cert template.\n");	CRMF_DestroyCertRequest(certReq);	return 10;    }    validity.notBefore = &notBefore;    validity.notAfter  = NULL;    notBefore = PR_Now();    rv = CRMF_CertRequestSetTemplateField(certReq, crmfValidity,(void*)(&validity));    if (rv != SECSuccess) {        printf ("Could not add validity to cert template\n");	CRMF_DestroyCertRequest(certReq);	return 11;    }    spki = GetSubjectPubKeyInfo(privKey, pubKey);    if (spki == NULL) {        printf ("Could not create a Subject Public Key Info to add\n");	CRMF_DestroyCertRequest(certReq);	return 12;    }    rv = CRMF_CertRequestSetTemplateField(certReq, crmfPublicKey, (void*)spki);    SECKEY_DestroySubjectPublicKeyInfo(spki);    if (rv != SECSuccess) {        printf ("Could not add the public key to the template\n");	CRMF_DestroyCertRequest(certReq);	return 13;    }        caCert =       CERT_FindCertByNickname(CERT_GetDefaultCertDB(), 			      caCertName);    if (caCert == NULL) {        printf ("Could not find the certificate for %s\n", caCertName);        CRMF_DestroyCertRequest(certReq);	return 50;    }    issuerUID = GetRandomBitString();    subjectUID = GetRandomBitString();    CRMF_CertRequestSetTemplateField(certReq,crmfIssuerUID,  (void*)&issuerUID);    CRMF_CertRequestSetTemplateField(certReq,crmfSubjectUID, (void*)&subjectUID);    PORT_Free(issuerUID.data);    PORT_Free(subjectUID.data);    extInfo = GetExtensions();    CRMF_CertRequestSetTemplateField(certReq, crmfExtension, (void*)extInfo);    FreeExtInfo(extInfo);    encKey = CRMF_CreateEncryptedKeyWithEncryptedValue(*privKey, caCert);    CERT_DestroyCertificate(caCert);    if (encKey == NULL) {        printf ("Could not create Encrypted Key with Encrypted Value.\n");	return 14;    }    pkiArchOpt = CRMF_CreatePKIArchiveOptions(crmfEncryptedPrivateKey, encKey);    CRMF_DestroyEncryptedKey(encKey);    if (pkiArchOpt == NULL) {        printf ("Could not create PKIArchiveOptions.\n");	return 15;    }    rv  = CRMF_CertRequestSetPKIArchiveOptions(certReq, pkiArchOpt);    CRMF_DestroyPKIArchiveOptions(pkiArchOpt);    if (rv != SECSuccess) {        printf ("Could not add the PKIArchiveControl to Cert Request.\n");	return 16;    }    *inCertReq = certReq;    return 0;}