algID = getSignatureOidTag(privKey->keyType, hashAlgTag);
algID = SEC_GetSignatureAlgorithmOidTag(privKey->keyType, hashAlgTag);
SignCert(CERTCertDBHandle *handle, CERTCertificate *cert, PRBool selfsign,          SECOidTag hashAlgTag,         SECKEYPrivateKey *privKey, char *issuerNickName, void *pwarg){    SECItem der;    SECItem *result = NULL;    SECKEYPrivateKey *caPrivateKey = NULL;        SECStatus rv;    PRArenaPool *arena;    SECOidTag algID;    void *dummy;    if( !selfsign ) {      CERTCertificate *issuer = PK11_FindCertFromNickname(issuerNickName, pwarg);      if( (CERTCertificate *)NULL == issuer ) {        SECU_PrintError(progName, "unable to find issuer with nickname %s", 	                issuerNickName);        return (SECItem *)NULL;      }      privKey = caPrivateKey = PK11_FindKeyByAnyCert(issuer, pwarg);      CERT_DestroyCertificate(issuer);      if (caPrivateKey == NULL) {	SECU_PrintError(progName, "unable to retrieve key %s", issuerNickName);	return NULL;      }    }	    arena = cert->arena;    algID = getSignatureOidTag(privKey->keyType, hashAlgTag);    if (algID == SEC_OID_UNKNOWN) {	fprintf(stderr, "Unknown key or hash type for issuer.");	goto done;    }    rv = SECOID_SetAlgorithmID(arena, &cert->signature, algID, 0);    if (rv != SECSuccess) {	fprintf(stderr, "Could not set signature algorithm id.");	goto done;    }    /* we only deal with cert v3 here */    *(cert->version.data) = 2;    cert->version.len = 1;    der.len = 0;    der.data = NULL;    dummy = SEC_ASN1EncodeItem (arena, &der, cert,			 	SEC_ASN1_GET(CERT_CertificateTemplate));    if (!dummy) {	fprintf (stderr, "Could not encode certificate.\n");	goto done;    }    result = (SECItem *) PORT_ArenaZAlloc (arena, sizeof (SECItem));    if (result == NULL) {	fprintf (stderr, "Could not allocate item for certificate data.\n");	goto done;    }    rv = SEC_DerSignData(arena, result, der.data, der.len, privKey, algID);    if (rv != SECSuccess) {	fprintf (stderr, "Could not sign encoded certificate data.\n");	PORT_Free(result);	result = NULL;	goto done;    }    cert->derCert = *result;done:    if (caPrivateKey) {	SECKEY_DestroyPrivateKey(caPrivateKey);    }    return result;}