CertReferences.cpp
Go to the documentation of this file.00001
00010 #include "CertReferences.h"
00011 #include "components.h"
00012 #include "ToolkitUtils.h"
00013 #include "Buffer.h"
00014 #include "PKIFSCVPErrors.h"
00015 #include "SCVPException.h"
00016 #include "ASN1Helper.h"
00017 #include "OID.h"
00018 #include "PKCReference.h"
00019 #include "ACReference.h"
00020 #include "SCVP.h"
00021 #include "PKCReference.h"
00022 #include "ACReference.h"
00023
00024
00025 using namespace std;
00026
00028
00029 struct CPKIFCertReferencesImpl
00030 {
00031 CPKIFACReferenceListPtr m_acList;
00032 CPKIFPKCReferenceListPtr m_pkcList;
00033 };
00034
00036
00045 CPKIFCertReferences::CPKIFCertReferences() :m_impl(new CPKIFCertReferencesImpl)
00046 {
00047 LOG_STRING_DEBUG("CPKIFCertReferences::CPKIFCertReferences()", TOOLKIT_SCVP_ASN, 0, this);
00048
00049 }
00060 CPKIFCertReferences::CPKIFCertReferences(
00062 const CPKIFBufferPtr& certRef)
00063 :m_impl (new CPKIFCertReferencesImpl)
00064 {
00065 if(certRef == (CPKIFBuffer*)NULL || 0 == certRef->GetLength())
00066 {
00067 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00068 }
00069
00070 CACASNWRAPPER_CREATE(CertReferences, objPDU);
00071 objPDU.Decode(certRef->GetBuffer(), certRef->GetLength());
00072
00073 if(objPDU->t == T_CertReferences_pkcRefs)
00074 {
00075 CPKIFPKCReferenceListPtr revPKCRefList(new CPKIFPKCReferenceList());
00076 DListNode* cur = objPDU->u.pkcRefs->head;
00077 while(NULL != cur)
00078 {
00079 PKCReference* tmp = (PKCReference*)cur->data;
00080 CACASNWRAPPER_CREATE(PKCReference, objPDU);
00081 ASN1OpenType* data1 = objPDU.Encode(tmp);
00082 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00083 CPKIFPKCReferencePtr tmpPKCReference(new CPKIFPKCReference(tmpBuf));
00084
00085 if(NULL != data1)
00086 delete data1;
00087
00088
00089 revPKCRefList->push_back(tmpPKCReference);
00090
00091 cur = cur->next;
00092 }
00093 m_impl->m_pkcList = revPKCRefList;
00094 }
00095 else if(objPDU->t == T_CertReferences_acRefs)
00096 {
00097 CPKIFACReferenceListPtr revACRefList(new CPKIFACReferenceList());
00098 DListNode* cur = objPDU->u.acRefs->head;
00099 while(NULL != cur)
00100 {
00101 ACReference* tmp = (ACReference*)cur->data;
00102 CACASNWRAPPER_CREATE(ACReference, objPDU);
00103 ASN1OpenType* data1 = objPDU.Encode(tmp);
00104 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00105 CPKIFACReferencePtr tmpACReference(new CPKIFACReference(tmpBuf));
00106
00107 if(NULL != data1)
00108 delete data1;
00109 revACRefList->push_back(tmpACReference);
00110
00111 cur = cur->next;
00112 }
00113 m_impl->m_acList = revACRefList;
00114 }
00115
00116 }
00124 CPKIFCertReferences::~CPKIFCertReferences()
00125 {
00126 LOG_STRING_DEBUG("CPKIFCertReferences::~CPKIFCertReferences()", TOOLKIT_SCVP_ASN, 0, this);
00127
00128 if (m_impl) {
00129 delete m_impl;
00130 }
00131 }
00139 void CPKIFCertReferences::SetACList(
00141 CPKIFACReferenceListPtr& acList)
00142 {
00143 m_impl->m_acList = acList;
00144
00145 CPKIFPKCReferenceListPtr tmpList;
00146 m_impl->m_pkcList = tmpList;
00147 }
00155 void CPKIFCertReferences::GetACList(
00157 CPKIFACReferenceListPtr& acList) const
00158 {
00159 acList = m_impl->m_acList;
00160 }
00161
00169 void CPKIFCertReferences::SetPKCList(
00171 CPKIFPKCReferenceListPtr& pkc)
00172 {
00173 m_impl->m_pkcList = pkc;
00174
00175 CPKIFACReferenceListPtr tmpList;
00176 m_impl->m_acList = tmpList;
00177 }
00185 void CPKIFCertReferences::GetPKCList(
00187 CPKIFPKCReferenceListPtr& pkc) const
00188 {
00189 pkc = m_impl->m_pkcList;
00190 }
00191
00199 CERTTYPE CPKIFCertReferences::GetCertType()
00200 {
00201 if(m_impl->m_pkcList != (CPKIFPKCReferenceList*)NULL && m_impl->m_pkcList->empty())
00202 {
00203 return PKC;
00204 }
00205 else if(m_impl->m_acList != (CPKIFACReferenceList*)NULL && !m_impl->m_pkcList->empty())
00206 {
00207 return AC;
00208 }
00209
00210 return NONE;
00211 }