PKCReference.cpp

Go to the documentation of this file.
00001 
00010 #include "Certificate.h"
00011 #include "PKCReference.h"
00012 #include "PKIFSCVPErrors.h"
00013 #include "SCVPException.h"
00014 #include "ToolkitUtils.h"
00015 #include "IPKIFHashContext.h"
00016 #include "SCVP.h"
00017 #include "ASN1Helper.h"
00018 #include "SCVPCertID.h"
00019 #include <iostream>
00020 
00021 #include "boost/filesystem/fstream.hpp"
00022 #include "boost/filesystem/operations.hpp"
00023 namespace fs = boost::filesystem;
00024 
00025 using namespace std;
00026 
00027 
00029 
00030 struct CPKIFPKCReferenceImpl 
00031 {
00032     CPKIFCertificatePtr m_cert;
00033     CPKIFSCVPCertIDPtr m_sCVPCertID;
00034 };
00035 
00037 
00045 CPKIFPKCReference::CPKIFPKCReference() :m_impl(new CPKIFPKCReferenceImpl)
00046 {
00047     LOG_STRING_DEBUG("CPKIFPKCReference::CPKIFPKCReference()", TOOLKIT_SCVP_ASN, 0, this);
00048 
00049 }
00060 CPKIFPKCReference::CPKIFPKCReference(
00062     const CPKIFBufferPtr& pkcRef)
00063   :m_impl (new CPKIFPKCReferenceImpl)
00064 {
00065     if(pkcRef == (CPKIFBuffer*)NULL || 0 == pkcRef->GetLength())
00066     {
00067         throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00068     }
00069 
00070     CACASNWRAPPER_CREATE(PKCReference, objPDU);
00071     objPDU.Decode(pkcRef->GetBuffer(), pkcRef->GetLength());
00072 
00073 
00074     if(objPDU->t == T_PKCReference_cert)
00075     {
00076         CACASNWRAPPER_CREATE(CACX509V3Certificate, certObjPDU);
00077         ASN1OpenType* certEncoded = NULL;
00078         certEncoded = certObjPDU.Encode(objPDU->u.cert);
00079         
00080         CPKIFCertificatePtr tmpCert(new CPKIFCertificate());
00081         tmpCert->Decode(certEncoded->data, certEncoded->numocts);
00082 
00083 
00084         if(certEncoded != NULL)
00085             delete certEncoded;
00086 
00087         m_impl->m_cert = tmpCert;
00088     }
00089     else if(objPDU->t == T_PKCReference_pkcRef)
00090     {
00091         CACASNWRAPPER_CREATE(SCVPCertID, objPDU2);
00092         ASN1OpenType* data1 = objPDU2.Encode(objPDU->u.pkcRef);
00093         CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00094         CPKIFSCVPCertIDPtr tmpSCVPCertID(new CPKIFSCVPCertID(tmpBuf));
00095         
00096         if(NULL != data1)
00097             delete data1;
00098 
00099     }
00100 
00101 }
00109 CPKIFPKCReference::~CPKIFPKCReference()
00110 {
00111     LOG_STRING_DEBUG("CPKIFPKCReference::~CPKIFPKCReference()", TOOLKIT_SCVP_ASN, 0, this);
00112 
00113     if (m_impl) {
00114       delete m_impl;
00115     }   
00116 }
00124 void CPKIFPKCReference::SetCert(
00126     CPKIFCertificatePtr& cert)
00127 {
00128     m_impl->m_cert = cert;
00129 
00130     
00131     CPKIFSCVPCertIDPtr tmp;
00132     m_impl->m_sCVPCertID = tmp;
00133 
00134 }
00142 CPKIFCertificatePtr CPKIFPKCReference::GetCert()
00143 {
00144     return m_impl->m_cert;
00145 }
00153 void CPKIFPKCReference::SetSCVPCertID(
00155     CPKIFSCVPCertIDPtr& sCVPCertID)
00156 {
00157     m_impl->m_sCVPCertID = sCVPCertID;
00158 
00159     CPKIFCertificatePtr tmp;
00160     m_impl->m_cert = tmp;
00161 }
00169 CPKIFSCVPCertIDPtr CPKIFPKCReference::GetSCVPCertID()
00170 {
00171     return m_impl->m_sCVPCertID;
00172 }
00173 
00181 REFERENCETYPE CPKIFPKCReference::GetRefType()
00182 {
00183     if(m_impl->m_cert != (CPKIFCertificate*)NULL)
00184     {
00185         return REFERENCETYPE_CERT;
00186     }
00187     else if(m_impl->m_sCVPCertID != (CPKIFSCVPCertID*)NULL)
00188     {
00189         return REFERENCETYPE_PKCREF;
00190     }
00191 
00192     return REFERENCETYPE_NONE;
00193 }

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