certUsageEmailRecipient, PR_FALSE, NULL))
certUsageEmailRecipient, PR_FALSE, &pwdata))
signed_data(struct signOptionsStr *signOptions){    NSSCMSMessage *cmsg = NULL;    NSSCMSContentInfo *cinfo;    NSSCMSSignedData *sigd;    NSSCMSSignerInfo *signerinfo;    CERTCertificate *cert= NULL, *ekpcert = NULL;    if (cms_verbose) {	fprintf(stderr, "Input to signed_data:\n");	if (signOptions->options->password)	    fprintf(stderr, "password [%s]\n", signOptions->options->password);	else	    fprintf(stderr, "password [NULL]\n");	fprintf(stderr, "certUsage [%d]\n", signOptions->options->certUsage);	if (signOptions->options->certHandle)	    fprintf(stderr, "certdb [%p]\n", signOptions->options->certHandle);	else	    fprintf(stderr, "certdb [NULL]\n");	if (signOptions->nickname)	    fprintf(stderr, "nickname [%s]\n", signOptions->nickname);	else	    fprintf(stderr, "nickname [NULL]\n");    }    if (signOptions->nickname == NULL) {	fprintf(stderr,         "ERROR: please indicate the nickname of a certificate to sign with.\n");	return NULL;    }    if ((cert = CERT_FindUserCertByUsage(signOptions->options->certHandle,                                          signOptions->nickname,                                         signOptions->options->certUsage,                                         PR_FALSE,                                         NULL)) == NULL) {	SECU_PrintError(progName, 	                "the corresponding cert for key \"%s\" does not exist",	                signOptions->nickname);	return NULL;    }    if (cms_verbose) {	fprintf(stderr, "Found certificate for %s\n", signOptions->nickname);    }    /*     * create the message object     */    cmsg = NSS_CMSMessage_Create(NULL); /* create a message on its own pool */    if (cmsg == NULL) {	fprintf(stderr, "ERROR: cannot create CMS message.\n");	return NULL;    }    /*     * build chain of objects: message->signedData->data     */    if ((sigd = NSS_CMSSignedData_Create(cmsg)) == NULL) {	fprintf(stderr, "ERROR: cannot create CMS signedData object.\n");	goto loser;    }    cinfo = NSS_CMSMessage_GetContentInfo(cmsg);    if (NSS_CMSContentInfo_SetContent_SignedData(cmsg, cinfo, sigd)           != SECSuccess) {	fprintf(stderr, "ERROR: cannot attach CMS signedData object.\n");	goto loser;    }    cinfo = NSS_CMSSignedData_GetContentInfo(sigd);    /* we're always passing data in and detaching optionally */    if (NSS_CMSContentInfo_SetContent_Data(cmsg, cinfo, NULL,                                            signOptions->detached)           != SECSuccess) {	fprintf(stderr, "ERROR: cannot attach CMS data object.\n");	goto loser;    }    /*      * create & attach signer information     */    signerinfo = NSS_CMSSignerInfo_Create(cmsg, cert, signOptions->hashAlgTag);    if (signerinfo == NULL) {	fprintf(stderr, "ERROR: cannot create CMS signerInfo object.\n");	goto loser;    }    if (cms_verbose) {	fprintf(stderr,		 "Created CMS message, added signed data w/ signerinfo\n");    }    /* we want the cert chain included for this one */    if (NSS_CMSSignerInfo_IncludeCerts(signerinfo, NSSCMSCM_CertChain,                                        signOptions->options->certUsage)           != SECSuccess) {	fprintf(stderr, "ERROR: cannot find cert chain.\n");	goto loser;    }    if (cms_verbose) {	fprintf(stderr, "imported certificate\n");    }    if (signOptions->signingTime) {	if (NSS_CMSSignerInfo_AddSigningTime(signerinfo, PR_Now()) 	      != SECSuccess) {	    fprintf(stderr, "ERROR: cannot add signingTime attribute.\n");	    goto loser;	}    }    if (signOptions->smimeProfile) {	if (NSS_CMSSignerInfo_AddSMIMECaps(signerinfo) != SECSuccess) {	    fprintf(stderr, "ERROR: cannot add SMIMECaps attribute.\n");	    goto loser;	}    }    if (!signOptions->encryptionKeyPreferenceNick) {	/* check signing cert for fitness as encryption cert */        SECStatus FitForEncrypt = CERT_CheckCertUsage(cert,                                                      certUsageEmailRecipient);        if (SECSuccess == FitForEncrypt) {            /* if yes, add signing cert as EncryptionKeyPreference */            if (NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs(signerinfo, cert,                                               signOptions->options->certHandle)                  != SECSuccess) {                fprintf(stderr,                     "ERROR: cannot add default SMIMEEncKeyPrefs attribute.\n");                goto loser;            }            if (NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs(signerinfo, cert,                                               signOptions->options->certHandle)                  != SECSuccess) {                fprintf(stderr,                     "ERROR: cannot add default MS SMIMEEncKeyPrefs attribute.\n");                goto loser;            }        } else {            /* this is a dual-key cert case, we need to look for the encryption               certificate under the same nickname as the signing cert */            /* get the cert, add it to the message */            if ((ekpcert = CERT_FindUserCertByUsage(                                              signOptions->options->certHandle,                                              signOptions->nickname,                                              certUsageEmailRecipient,                                              PR_FALSE,                                              NULL)) == NULL) {                SECU_PrintError(progName,                          "the corresponding cert for key \"%s\" does not exist",                         signOptions->encryptionKeyPreferenceNick);                goto loser;            }            if (NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs(signerinfo, ekpcert,                                               signOptions->options->certHandle)                  != SECSuccess) {                fprintf(stderr,                         "ERROR: cannot add SMIMEEncKeyPrefs attribute.\n");                goto loser;            }            if (NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs(signerinfo, ekpcert,                                               signOptions->options->certHandle)                  != SECSuccess) {                fprintf(stderr,                         "ERROR: cannot add MS SMIMEEncKeyPrefs attribute.\n");                goto loser;            }            if (NSS_CMSSignedData_AddCertificate(sigd, ekpcert) != SECSuccess) {                fprintf(stderr, "ERROR: cannot add encryption certificate.\n");                goto loser;            }        }    } else if (PL_strcmp(signOptions->encryptionKeyPreferenceNick, "NONE") == 0) {        /* No action */    } else {	/* get the cert, add it to the message */	if ((ekpcert = CERT_FindUserCertByUsage(                                     signOptions->options->certHandle, 	                             signOptions->encryptionKeyPreferenceNick,                                     certUsageEmailRecipient, PR_FALSE, NULL))	      == NULL) {	    SECU_PrintError(progName, 	               "the corresponding cert for key \"%s\" does not exist",	                signOptions->encryptionKeyPreferenceNick);	    goto loser;	}	if (NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs(signerinfo, ekpcert, 	                                     signOptions->options->certHandle)	      != SECSuccess) {	    fprintf(stderr, "ERROR: cannot add SMIMEEncKeyPrefs attribute.\n");	    goto loser;	}	if (NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs(signerinfo, ekpcert, 	                                     signOptions->options->certHandle)	      != SECSuccess) {	    fprintf(stderr, "ERROR: cannot add MS SMIMEEncKeyPrefs attribute.\n");	    goto loser;	}	if (NSS_CMSSignedData_AddCertificate(sigd, ekpcert) != SECSuccess) {	    fprintf(stderr, "ERROR: cannot add encryption certificate.\n");	    goto loser;	}    }    if (NSS_CMSSignedData_AddSignerInfo(sigd, signerinfo) != SECSuccess) {	fprintf(stderr, "ERROR: cannot add CMS signerInfo object.\n");	goto loser;    }    if (cms_verbose) {	fprintf(stderr, "created signed-data message\n");    }    if (ekpcert) {	CERT_DestroyCertificate(ekpcert);    }    if (cert) {	CERT_DestroyCertificate(cert);    }    return cmsg;loser:    if (ekpcert) {	CERT_DestroyCertificate(ekpcert);    }    if (cert) {	CERT_DestroyCertificate(cert);    }    NSS_CMSMessage_Destroy(cmsg);    return NULL;}