CertBundle.cpp

Go to the documentation of this file.
00001 
00010 #include "Certificate.h"
00011 #include "CertBundle.h"
00012 #include "PKIFSCVPErrors.h"
00013 #include "SCVPException.h"
00014 #include "ToolkitUtils.h"
00015 #include "SCVP.h"
00016 #include "ASN1Helper.h"
00017 
00019 
00020 struct CPKIFCertBundleImpl 
00021 {
00022     CPKIFCertificateListPtr m_certList;
00023 };
00024 
00026 
00034 CPKIFCertBundle::CPKIFCertBundle() :m_impl(new CPKIFCertBundleImpl)
00035 {
00036     LOG_STRING_DEBUG("CPKIFCertBundle::CPKIFCertBundle()", TOOLKIT_SCVP_ASN, 0, this);
00037 
00038 }
00046 CPKIFCertBundle::~CPKIFCertBundle()
00047 {
00048     LOG_STRING_DEBUG("CPKIFCertBundle::~CPKIFCertBundle()", TOOLKIT_SCVP_ASN, 0, this);
00049 
00050     if (m_impl) {
00051       delete m_impl;
00052     }   
00053 }
00061 void CPKIFCertBundle::Decode(
00063     CPKIFBufferPtr& bundle)
00064 {
00065     CACASNWRAPPER_CREATE(CertBundle, objPDU);
00066     objPDU.Decode(bundle->GetBuffer(), bundle->GetLength());
00067 
00068     CPKIFCertificateListPtr certList(new CPKIFCertificateList());
00069     DListNode* cur = objPDU->head;
00070     while(NULL != cur)
00071     {
00072         ASN1OpenType* tmp = (ASN1OpenType*)cur->data;
00073         CPKIFCertificatePtr tmpCert(new CPKIFCertificate());
00074         tmpCert->Decode(tmp->data, tmp->numocts);
00075 
00076         certList->push_back(tmpCert);
00077 
00078         cur = cur->next;
00079     }
00080     m_impl->m_certList = certList;
00081 }
00089 CPKIFBufferPtr CPKIFCertBundle::Encode()
00090 {
00091     CertBundle bundle;
00092     bundle.count = 0;
00093     bundle.head = NULL;
00094     bundle.tail = NULL;
00095     
00096     CPKIFBufferPtr rv;
00097     
00098     if(m_impl->m_certList != (CPKIFCertificateList*)NULL && !m_impl->m_certList->empty())
00099     {
00100         DListNode* curCert = NULL;
00101         CPKIFCertificateList::iterator certPos; 
00102         CPKIFCertificateList::iterator certEnd = m_impl->m_certList->end();
00103         for(certPos = m_impl->m_certList->begin(); certPos != certEnd; ++certPos)
00104         {
00105             if(NULL == curCert)
00106             {
00107                 NEW_NODE(curCert)
00108             }
00109             else
00110             {
00111                 NEW_NEXT_AND_ADVANCE(curCert)
00112             }
00113 
00114             ASN1OpenType* tmpCert = new ASN1OpenType;
00115             memset(tmpCert, 0, sizeof(ASN1OpenType));
00116             
00117             //certs were screened when added to make sure the encoded buffer existed
00118             tmpCert->data = (*certPos)->Encoded()->GetBuffer();
00119             tmpCert->numocts = (*certPos)->Encoded()->GetLength();
00120             
00121             curCert->data = tmpCert;
00122 
00123             SET_HEAD_TAIL_INCREMENT(bundle, curCert)
00124         }
00125         
00126         CACASNWRAPPER_CREATE(CertBundle, objPDU);
00127         ASN1OpenType* data1 = objPDU.Encode(&bundle);
00128         CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00129 
00130         DListNode* cur = NULL, *tmp = NULL;
00131         cur = bundle.head;
00132         while(NULL != cur)
00133         {
00134             tmp = cur->next;
00135             if(NULL != cur && NULL != cur->data)
00136                 delete cur->data;
00137             delete cur;
00138             cur = tmp;
00139         }
00140 
00141         if(data1 != NULL)
00142             delete data1;
00143 
00144         rv = tmpBuf;
00145     }
00146     
00147     return rv;
00148 }
00149 
00157  void CPKIFCertBundle::SetCertList(
00159      CPKIFCertificateListPtr& list)
00160 {
00161     m_impl->m_certList = list;
00162 }
00163 
00171 void CPKIFCertBundle::GetCertList(
00173      CPKIFCertificateListPtr& list)
00174 {
00175     list = m_impl->m_certList;
00176 }

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