EvidenceRecordBundle.cpp
Go to the documentation of this file.00001
00010 #include "EvidenceRecord.h"
00011 #include "EvidenceRecordBundle.h"
00012 #include "PKIFMessageErrors.h"
00013 #include "PKIFException.h"
00014 #include "ToolkitUtils.h"
00015 #include "Buffer.h"
00016 #include "SCVP.h"
00017 #include "ASN1Helper.h"
00018
00020
00021 struct CPKIFEvidenceRecordBundleImpl
00022 {
00023 CPKIFEvidenceRecordListPtr m_erList;
00024 };
00025
00027
00035 CPKIFEvidenceRecordBundle::CPKIFEvidenceRecordBundle() :m_impl(new CPKIFEvidenceRecordBundleImpl)
00036 {
00037 LOG_STRING_DEBUG("CPKIFEvidenceRecordBundle::CPKIFEvidenceRecordBundle()", TOOLKIT_SCVP_ASN, 0, this);
00038
00039 }
00047 CPKIFEvidenceRecordBundle::~CPKIFEvidenceRecordBundle()
00048 {
00049 LOG_STRING_DEBUG("CPKIFEvidenceRecordBundle::~CPKIFEvidenceRecordBundle()", TOOLKIT_SCVP_ASN, 0, this);
00050
00051 if (m_impl) {
00052 delete m_impl;
00053 }
00054 }
00062 void CPKIFEvidenceRecordBundle::Decode(
00064 CPKIFBufferPtr& bundle)
00065 {
00066 CACASNWRAPPER_CREATE(CertBundle, objPDU);
00067 objPDU.Decode(bundle->GetBuffer(), bundle->GetLength());
00068
00069 CPKIFEvidenceRecordListPtr erList(new CPKIFEvidenceRecordList());
00070 DListNode* cur = objPDU->head;
00071 while(NULL != cur)
00072 {
00073 ASN1OpenType* tmp = (ASN1OpenType*)cur->data;
00074 CPKIFEvidenceRecordPtr tmpER(new CPKIFEvidenceRecord());
00075 CPKIFBufferPtr tmpBuff(new CPKIFBuffer(tmp->data, tmp->numocts));
00076 tmpER->Decode(tmpBuff);
00077
00078 erList->push_back(tmpER);
00079
00080 cur = cur->next;
00081 }
00082 m_impl->m_erList = erList;
00083 }
00091 CPKIFBufferPtr CPKIFEvidenceRecordBundle::Encode()
00092 {
00093 CertBundle bundle;
00094 memset(&bundle, 0, sizeof(CertBundle));
00095
00096 CPKIFBufferPtr rv;
00097
00098 if(m_impl->m_erList != (CPKIFEvidenceRecordList*)NULL && !m_impl->m_erList->empty())
00099 {
00100 DListNode* curER = NULL;
00101 CPKIFEvidenceRecordList::iterator erPos;
00102 CPKIFEvidenceRecordList::iterator erEnd = m_impl->m_erList->end();
00103 for(erPos = m_impl->m_erList->begin(); erPos != erEnd; ++erPos)
00104 {
00105 if(NULL == curER)
00106 {
00107 NEW_NODE(curER)
00108 }
00109 else
00110 {
00111 NEW_NEXT_AND_ADVANCE(curER)
00112 }
00113
00114 ASN1OpenType* tmpER = new ASN1OpenType;
00115 memset(tmpER, 0, sizeof(ASN1OpenType));
00116
00117
00118 CPKIFBufferPtr encoded = (*erPos)->Encode();
00119
00120 tmpER->data = encoded->GetBuffer();
00121 tmpER->numocts = encoded->GetLength();
00122
00123 curER->data = tmpER;
00124
00125 SET_HEAD_TAIL_INCREMENT(bundle, curER)
00126 }
00127
00128 CACASNWRAPPER_CREATE(CertBundle, objPDU);
00129 ASN1OpenType* data1 = objPDU.Encode(&bundle);
00130 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00131
00132 rv = tmpBuf;
00133 }
00134
00135 return rv;
00136 }
00137
00145 void CPKIFEvidenceRecordBundle::SetERList(
00147 CPKIFEvidenceRecordListPtr& list)
00148 {
00149 m_impl->m_erList = list;
00150 }
00151
00159 void CPKIFEvidenceRecordBundle::GetERList(
00161 CPKIFEvidenceRecordListPtr& list)
00162 {
00163 list = m_impl->m_erList;
00164 }