PORT_Assert(digestalgs); PORT_Assert(digests); PORT_Assert(sigd);
NSS_CMSSignedData_SetDigests(NSSCMSSignedData *sigd,				SECAlgorithmID **digestalgs,				SECItem **digests){    int cnt, i, idx;    PORT_Assert(digestalgs);    PORT_Assert(digests);    PORT_Assert(sigd);    if (!sigd || !digestalgs || !digests) {        PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);        return SECFailure;    }    if (sigd->digestAlgorithms == NULL) {	PORT_SetError(SEC_ERROR_INVALID_ARGS);	return SECFailure;    }    /* we assume that the digests array is just not there yet */    PORT_Assert(sigd->digests == NULL);    if (sigd->digests != NULL) {	PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);	return SECFailure;    }    /* now allocate one (same size as digestAlgorithms) */    cnt = NSS_CMSArray_Count((void **)sigd->digestAlgorithms);    sigd->digests = PORT_ArenaZAlloc(sigd->cmsg->poolp, (cnt + 1) * sizeof(SECItem *));    if (sigd->digests == NULL) {	PORT_SetError(SEC_ERROR_NO_MEMORY);	return SECFailure;    }    for (i = 0; sigd->digestAlgorithms[i] != NULL; i++) {	/* try to find the sigd's i'th digest algorithm in the array we passed in */	idx = NSS_CMSAlgArray_GetIndexByAlgID(digestalgs, sigd->digestAlgorithms[i]);	if (idx < 0) {	    PORT_SetError(SEC_ERROR_DIGEST_NOT_FOUND);	    return SECFailure;	}	if (!digests[idx]) {	    /* We have no digest for this algorithm, probably because it is 	    ** unrecognized or unsupported.  We'll ignore this here.  If this 	    ** digest is needed later, an error will be be generated then.	    */	    continue;	}	/* found it - now set it */	if ((sigd->digests[i] = SECITEM_AllocItem(sigd->cmsg->poolp, NULL, 0)) == NULL ||	    SECITEM_CopyItem(sigd->cmsg->poolp, sigd->digests[i], digests[idx]) != SECSuccess)	{	    PORT_SetError(SEC_ERROR_NO_MEMORY);	    return SECFailure;	}    }    return SECSuccess;}