SECItem * NSS_CMSContentInfo_GetInnerContent(NSSCMSContentInfo *cinfo) { NSSCMSContentInfo *ccinfo; SECOidTag tag; SECItem *pItem = NULL; if (cinfo == NULL) { return NULL; } tag = NSS_CMSContentInfo_GetContentTypeTag(cinfo); if (NSS_CMSType_IsData(tag)) { pItem = cinfo->content.data; } else if (NSS_CMSType_IsWrapper(tag)) { ccinfo = NSS_CMSContentInfo_GetChildContentInfo(cinfo); if (ccinfo != NULL) { pItem = NSS_CMSContentInfo_GetContent(ccinfo); } } else { PORT_Assert(0); } return pItem; }
/* * NSS_CMSDigestedData_Encode_BeforeStart - do all the necessary things to a DigestedData * before encoding begins. * * In particular: * - set the right version number. The contentInfo's content type must be set up already. */ SECStatus NSS_CMSDigestedData_Encode_BeforeStart(NSSCMSDigestedData *digd) { unsigned long version; SECItem *dummy; version = NSS_CMS_DIGESTED_DATA_VERSION_DATA; if (!NSS_CMSType_IsData(NSS_CMSContentInfo_GetContentTypeTag( &(digd->contentInfo)))) version = NSS_CMS_DIGESTED_DATA_VERSION_ENCAP; dummy = SEC_ASN1EncodeInteger(digd->cmsg->poolp, &(digd->version), version); return (dummy == NULL) ? SECFailure : SECSuccess; }
/* * NSS_CMSMessage_ContainsCertsOrCrls - see if message contains certs along the way */ PRBool NSS_CMSMessage_ContainsCertsOrCrls(NSSCMSMessage *cmsg) { NSSCMSContentInfo *cinfo; /* descend into CMS message */ for (cinfo = &(cmsg->contentInfo); cinfo != NULL; cinfo = NSS_CMSContentInfo_GetChildContentInfo(cinfo)) { if (!NSS_CMSType_IsData(NSS_CMSContentInfo_GetContentTypeTag(cinfo))) continue; /* next level */ if (NSS_CMSSignedData_ContainsCertsOrCrls(cinfo->content.signedData)) return PR_TRUE; /* callback here for generic wrappers? */ } return PR_FALSE; }
/* * NSS_CMSContentInfo_GetContent - get pointer to inner content * * needs to be casted... */ void * NSS_CMSContentInfo_GetContent(NSSCMSContentInfo *cinfo) { if (cinfo == NULL) { return NULL; } SECOidTag tag = cinfo->contentTypeTag ? cinfo->contentTypeTag->offset : SEC_OID_UNKNOWN; switch (tag) { case SEC_OID_PKCS7_DATA: case SEC_OID_PKCS7_SIGNED_DATA: case SEC_OID_PKCS7_ENVELOPED_DATA: case SEC_OID_PKCS7_DIGESTED_DATA: case SEC_OID_PKCS7_ENCRYPTED_DATA: return cinfo->content.pointer; default: return NSS_CMSType_IsWrapper(tag) ? cinfo->content.pointer : (NSS_CMSType_IsData(tag) ? cinfo->rawContent : NULL); } }
/* * NSS_CMSContentInfo_SetContent - set content type & content */ SECStatus NSS_CMSContentInfo_SetContent(NSSCMSMessage *cmsg, NSSCMSContentInfo *cinfo, SECOidTag type, void *ptr) { SECStatus rv; if (cinfo == NULL || cmsg == NULL) { return SECFailure; } cinfo->contentTypeTag = SECOID_FindOIDByTag(type); if (cinfo->contentTypeTag == NULL) { return SECFailure; } /* do not copy the oid, just create a reference */ rv = SECITEM_CopyItem(cmsg->poolp, &(cinfo->contentType), &(cinfo->contentTypeTag->oid)); if (rv != SECSuccess) { return SECFailure; } cinfo->content.pointer = ptr; if (NSS_CMSType_IsData(type) && ptr) { cinfo->rawContent = ptr; } else { /* as we always have some inner data, * we need to set it to something, just to fool the encoder enough to work on it * and get us into nss_cms_encoder_notify at that point */ cinfo->rawContent = SECITEM_AllocItem(cmsg->poolp, NULL, 1); if (cinfo->rawContent == NULL) { PORT_SetError(SEC_ERROR_NO_MEMORY); return SECFailure; } } return SECSuccess; }