CertReference.cpp
Go to the documentation of this file.00001
00010 #include "CertReference.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
00022
00023 using namespace std;
00024
00026
00027 struct CPKIFCertReferenceImpl
00028 {
00029 CPKIFACReferencePtr m_ac;
00030 CPKIFPKCReferencePtr m_pkc;
00031 };
00032
00034
00043 CPKIFCertReference::CPKIFCertReference() :m_impl(new CPKIFCertReferenceImpl)
00044 {
00045 LOG_STRING_DEBUG("CPKIFCertReference::CPKIFCertReference()", TOOLKIT_SCVP_ASN, 0, this);
00046
00047 }
00058 CPKIFCertReference::CPKIFCertReference(
00060 const CPKIFBufferPtr& certRef)
00061 :m_impl (new CPKIFCertReferenceImpl)
00062 {
00063 if(certRef == (CPKIFBuffer*)NULL || 0 == certRef->GetLength())
00064 {
00065 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00066 }
00067
00068 CACASNWRAPPER_CREATE(CertReference, objPDU);
00069 objPDU.Decode(certRef->GetBuffer(), certRef->GetLength());
00070
00071 if(objPDU->t == T_CertReference_pkc)
00072 {
00073 CACASNWRAPPER_CREATE(PKCReference, objPDU2);
00074 ASN1OpenType* data1 = objPDU2.Encode(objPDU->u.pkc);
00075 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00076 CPKIFPKCReferencePtr tmpPKCReference(new CPKIFPKCReference(tmpBuf));
00077
00078 m_impl->m_pkc = tmpPKCReference;
00079 }
00080 else if(objPDU->t == T_CertReference_ac)
00081 {
00082 CACASNWRAPPER_CREATE(ACReference, objPDU2);
00083 ASN1OpenType* data1 = objPDU2.Encode(objPDU->u.ac);
00084 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00085 CPKIFACReferencePtr tmpACReference(new CPKIFACReference(tmpBuf));
00086
00087 m_impl->m_ac = tmpACReference;
00088 }
00089 }
00097 CPKIFCertReference::~CPKIFCertReference()
00098 {
00099 LOG_STRING_DEBUG("CPKIFCertReference::~CPKIFCertReference()", TOOLKIT_SCVP_ASN, 0, this);
00100
00101 if (m_impl) {
00102 delete m_impl;
00103 }
00104 }
00112 void CPKIFCertReference::SetAC(
00114 CPKIFACReferencePtr& ac)
00115 {
00116 m_impl->m_ac = ac;
00117
00118 CPKIFPKCReferencePtr tmp;
00119 m_impl->m_pkc = tmp;
00120 }
00128 const CPKIFACReferencePtr CPKIFCertReference::GetAC() const
00129 {
00130 return m_impl->m_ac;
00131 }
00132
00140 void CPKIFCertReference::SetPKC(
00142 CPKIFPKCReferencePtr& pkc)
00143 {
00144 m_impl->m_pkc = pkc;
00145
00146 CPKIFACReferencePtr tmp;
00147 m_impl->m_ac = tmp;
00148 }
00156 const CPKIFPKCReferencePtr CPKIFCertReference::GetPKC() const
00157 {
00158 return m_impl->m_pkc;
00159 }
00160
00168 CERTREFERENCES CPKIFCertReference::GetCertRefType()
00169 {
00170 if(m_impl->m_pkc != (CPKIFPKCReference*)NULL)
00171 {
00172 return CERTREFERENCES_PKC;
00173 }
00174 else if(m_impl->m_ac != (CPKIFACReference*)NULL)
00175 {
00176 return CERTREFERENCES_AC;
00177 }
00178
00179 return CERTREFERENCES_NONE;
00180 }