PKIFCMSMessageMemoryHelper.cpp

Go to the documentation of this file.
00001 
00009 #include "PKIFCMSMessageMemoryHelper.h"
00010 #include "CryptographicMessageSyntax2004.h"
00011 
00019 void FreeSignerInfo(
00021     CACCMSSignerInfo* tmpSI)
00022 {
00023     if(!tmpSI)
00024         return;
00025 
00026     if(2 == tmpSI->sid.t)
00027     {
00028         if(NULL != tmpSI->sid.u.subjectKeyIdentifier->data)
00029             delete[] tmpSI->sid.u.subjectKeyIdentifier->data;
00030 
00031         if(NULL != tmpSI->sid.u.subjectKeyIdentifier)
00032             delete tmpSI->sid.u.subjectKeyIdentifier;
00033     }
00034     else if(1 == tmpSI->sid.t)
00035     {
00036         if(NULL != tmpSI->sid.u.issuerAndSerialNumber)
00037         {
00038             DListNode* cur = NULL, *tmp = NULL;
00039             cur = tmpSI->sid.u.issuerAndSerialNumber->issuer.u.rdnSequence->head;
00040             while(NULL != cur)
00041             {
00042                 tmp = cur->next;
00043                 ASN1OpenType* tmpOpenType = (ASN1OpenType*)cur->data;
00044 
00045                 if(NULL != tmpOpenType->data)
00046                     delete[] tmpOpenType->data;
00047                 if(NULL != cur && NULL != cur->data)
00048                     delete cur->data;
00049                 delete cur;
00050                 cur = tmp;
00051             }
00052             delete tmpSI->sid.u.issuerAndSerialNumber->issuer.u.rdnSequence;
00053             delete tmpSI->sid.u.issuerAndSerialNumber;
00054         }
00055     }
00056 
00057     if(tmpSI->signatureAlgorithm.m.parametersPresent && NULL != tmpSI->signatureAlgorithm.parameters.data)
00058         delete[] tmpSI->signatureAlgorithm.parameters.data;
00059 
00060     if(NULL != tmpSI->signature.data)
00061         delete[] tmpSI->signature.data;
00062 
00063     if(tmpSI->m.signedAttrsPresent)
00064     {
00065         DListNode* cur3 = NULL, *tmp3 = NULL;
00066         cur3 = tmpSI->signedAttrs.head;
00067         while(NULL != cur3)
00068         {
00069             CACCMSAttribute* tmpAttr = (CACCMSAttribute*)cur3->data;
00070             
00071 
00072             if(tmpAttr->attrValues.data)
00073                 delete[] tmpAttr->attrValues.data;
00074 
00075             delete tmpAttr;
00076 
00077             tmp3 = cur3->next;
00078             delete cur3;
00079             cur3 = tmp3;
00080         }
00081     }
00082 
00083     if(tmpSI->m.unsignedAttrsPresent)
00084     {
00085         DListNode* cur3 = NULL, *tmp3 = NULL;
00086         cur3 = tmpSI->unsignedAttrs.head;
00087         while(NULL != cur3)
00088         {
00089             CACCMSAttribute* tmpAttr = (CACCMSAttribute*)cur3->data;
00090             
00091             if(tmpAttr->attrValues.data)
00092                 delete[] tmpAttr->attrValues.data;
00093             delete tmpAttr;
00094 
00095             tmp3 = cur3->next;
00096             delete cur3;
00097             cur3 = tmp3;
00098         }
00099     }
00100 }
00108 void FreeSignedDataMembers(
00110     CACCMSSignedData* pSignedData)
00111 {
00112     DListNode* cur = NULL, *tmp = NULL;
00113 
00114     if(pSignedData->m.certificatesPresent)
00115     {
00116         cur = pSignedData->certificates.head;
00117         while(NULL != cur)
00118         {
00119             CACCMSCertificateChoices* curChoice = (CACCMSCertificateChoices*)cur->data;
00120             CACX509V3Certificate* tmpCert = (CACX509V3Certificate*)curChoice->u.certificate;
00121             delete tmpCert;
00122             delete curChoice;
00123 
00124             tmp = cur->next;
00125             delete cur;
00126             cur = tmp;
00127         }
00128     }
00129 
00130     if(pSignedData->m.crlsPresent)
00131     {
00132         cur = pSignedData->crls.head;
00133         while(NULL != cur)
00134         {
00135             CACCMSRevocationInfoChoice* curChoice = (CACCMSRevocationInfoChoice*)cur->data;
00136 
00137             CACX509V3CertificateList* tmpCert = (CACX509V3CertificateList*)curChoice->u.crl;
00138             delete tmpCert;
00139             delete curChoice;
00140 
00141             tmp = cur->next;
00142             delete cur;
00143             cur = tmp;
00144         }
00145     }
00146 
00147     cur = pSignedData->digestAlgorithms.head;
00148     while(NULL != cur)
00149     {
00150         CACX509V3AlgorithmIdentifier* tmpDA = (CACX509V3AlgorithmIdentifier*)cur->data;
00151         delete tmpDA;
00152 
00153         tmp = cur->next;
00154         delete cur;
00155         cur = tmp;
00156     }
00157 
00158     cur = pSignedData->signerInfos.head;
00159     while(NULL != cur)
00160     {
00161         CACCMSSignerInfo* tmpSI = (CACCMSSignerInfo*)cur->data;
00162 
00163         FreeSignerInfo(tmpSI);
00164         delete tmpSI;
00165 
00166         tmp = cur->next;
00167         delete cur;
00168         cur = tmp;
00169     }
00170 }
00178 void FreeEnvelopedDataMembers(
00180     CACCMSEnvelopedData* pEnvelopedData)
00181 {
00182     DListNode* cur = NULL, *tmp = NULL;
00183 
00184     if(pEnvelopedData->m.originatorInfoPresent)
00185     {
00186         if(pEnvelopedData->originatorInfo.m.certsPresent)
00187         {
00188             cur = pEnvelopedData->originatorInfo.certs.head;
00189             while(NULL != cur)
00190             {
00191                 CACX509V3Certificate* tmpCert = (CACX509V3Certificate*)cur->data;
00192                 delete tmpCert;
00193 
00194                 tmp = cur->next;
00195                 delete cur;
00196                 cur = tmp;
00197             }
00198         }
00199         if(pEnvelopedData->originatorInfo.m.crlsPresent)
00200         {
00201             cur = pEnvelopedData->originatorInfo.crls.head;
00202             while(NULL != cur)
00203             {
00204                 CACX509V3CertificateList* tmpCert = (CACX509V3CertificateList*)cur->data;
00205                 delete tmpCert;
00206 
00207                 tmp = cur->next;
00208                 delete cur;
00209                 cur = tmp;
00210             }
00211         }
00212     }
00213 
00214     cur = pEnvelopedData->recipientInfos.head;
00215     while(NULL != cur)
00216     {
00217         CACCMSRecipientInfo* tmpRI = (CACCMSRecipientInfo*)cur->data;
00218         if(1 == tmpRI->t)
00219         {
00220             CACCMSKeyTransRecipientInfo* tmpKTRI = tmpRI->u.ktri;
00221             CACCMSIssuerAndSerialNumber* tmpIssDNSerNum = tmpKTRI->rid.u.issuerAndSerialNumber;
00222 
00223             delete[] tmpKTRI->encryptedKey.data;
00224             delete tmpIssDNSerNum;
00225             delete tmpKTRI;
00226         }
00227         else if(3 == tmpRI->t)
00228         {
00229             CACCMSKEKRecipientInfo* tmpKEKRI = tmpRI->u.kekri;
00230             if(tmpKEKRI->encryptedKey.data)
00231                 delete[] tmpKEKRI->encryptedKey.data;
00232             //added 11/11/2003
00233             if(tmpKEKRI->keyEncryptionAlgorithm.parameters.data)
00234                 delete[] tmpKEKRI->keyEncryptionAlgorithm.parameters.data;
00235             delete tmpKEKRI; //added 11/11/2003
00236         }
00237         delete tmpRI;
00238 
00239         tmp = cur->next;
00240         delete cur;
00241         cur = tmp;
00242     }
00243 
00244     if(pEnvelopedData->m.unprotectedAttrsPresent)
00245     {
00246         DListNode* cur2 = NULL, *tmp2 = NULL;
00247 
00248         cur = pEnvelopedData->unprotectedAttrs.head;
00249         while(NULL != cur)
00250         {
00251             if(NULL != cur->data)
00252             {
00253                 CACCMSAttribute* tmpAttr = (CACCMSAttribute*)cur->data;
00254 
00255                 //if(0 < tmpAttr->attrValues.count)
00256                 //{
00257                 //  cur2 = tmpAttr->attrValues.head;
00258                 //  while(NULL != cur2)
00259                 //  {
00260                 //      if(NULL != cur2->data)
00261                 //      {
00262                 //          ASN1OpenType* tmpOT = (ASN1OpenType*)cur2->data;
00263                 //          if(NULL != tmpOT->data)
00264                 //              delete[] tmpOT->data;
00265                 //          delete tmpOT;
00266                 //      }
00267 
00268                 //      tmp2 = cur2->next;
00269                 //      delete cur2;
00270                 //      cur2 = tmp2;
00271                 //  }
00272                 //}
00273                 if(tmpAttr->attrValues.data)
00274                     delete[] tmpAttr->attrValues.data;
00275 
00276                 delete tmpAttr;
00277             }
00278 
00279             tmp = cur->next;
00280             delete cur;
00281             cur = tmp;
00282         }
00283     }
00284 
00285     delete[] pEnvelopedData->encryptedContentInfo.encryptedContent.data;
00286     delete[] pEnvelopedData->encryptedContentInfo.contentEncryptionAlgorithm.parameters.data;
00287 }
00288 
00296 PKIFCMSMessageMemoryHelper::~PKIFCMSMessageMemoryHelper()
00297 {
00298     // clean up memory
00299     if (pContentInfo)
00300     {
00301         delete pContentInfo;
00302     }
00303     if (pSignedData)
00304     {
00305         FreeSignedDataMembers(pSignedData);
00306         delete pSignedData;
00307     }
00308     if (pEnvelopedData)
00309     {
00310         FreeEnvelopedDataMembers(pEnvelopedData);
00311         delete pEnvelopedData;
00312     }
00313     if (signedContentType)
00314     {
00315         delete signedContentType;
00316     }
00317     if (pSignerInfo)
00318     {
00319         FreeSignerInfo(pSignerInfo);
00320         delete pSignerInfo;
00321     }
00322     if(pEncryptedData)
00323     {
00324         if(pEncryptedData->encryptedContentInfo.contentEncryptionAlgorithm.parameters.data)
00325             delete[] pEncryptedData->encryptedContentInfo.contentEncryptionAlgorithm.parameters.data;
00326         if(pEncryptedData->encryptedContentInfo.encryptedContent.data)
00327             delete[] pEncryptedData->encryptedContentInfo.encryptedContent.data;
00328 
00329         if(pEncryptedData->m.unprotectedAttrsPresent)
00330         {
00331             DListNode* cur2 = NULL, *tmp2 = NULL, *cur = NULL, *tmp = NULL;
00332 
00333             cur = pEncryptedData->unprotectedAttrs.head;
00334             while(NULL != cur)
00335             {
00336                 if(NULL != cur->data)
00337                 {
00338                     CACCMSAttribute* tmpAttr = (CACCMSAttribute*)cur->data;
00339 
00340                     //if(0 < tmpAttr->attrValues.count)
00341                     //{
00342                     //  cur2 = tmpAttr->attrValues.head;
00343                     //  while(NULL != cur2)
00344                     //  {
00345                     //      if(NULL != cur2->data)
00346                     //      {
00347                     //          ASN1OpenType* tmpOT = (ASN1OpenType*)cur2->data;
00348                     //          if(NULL != tmpOT->data)
00349                     //              delete[] tmpOT->data;
00350                     //          delete tmpOT;
00351                     //      }
00352 
00353                     //      tmp2 = cur2->next;
00354                     //      delete cur2;
00355                     //      cur2 = tmp2;
00356                     //  }
00357                     //}
00358                     if (tmpAttr->attrValues.data)
00359                         delete [] tmpAttr->attrValues.data;
00360 
00361                     delete tmpAttr;
00362                 }
00363 
00364                 tmp = cur->next;
00365                 delete cur;
00366                 cur = tmp;
00367             }
00368         }
00369 
00370         delete pEncryptedData;
00371     }
00372 }
00380 PKIFCMSMessageMemoryHelper::PKIFCMSMessageMemoryHelper():pContentInfo(NULL), pSignedData(NULL),
00381                     pEnvelopedData(NULL), signedContentType(NULL), pSignerInfo(NULL), pEncryptedData(NULL)
00382                     
00383 {
00384 
00385 }
00386 

Generated on Mon Nov 15 11:15:54 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6