IssuerAndSerialNumber.cpp

Go to the documentation of this file.
00001 
00009 #include "IssuerAndSerialNumber.h"
00010 
00011 #include "Name.h"
00012 
00013 #include "ToolkitUtils.h"
00014 #include "components.h"
00015 #include "PKIFCommonErrors.h"
00016 #include "PKIFMessageException.h"
00017 #include "CryptographicMessageSyntax2004.h"
00018 #include "ASN1Helper.h"
00019 #include "Buffer.h"
00020 
00022 struct CPKIFIssuerAndSerialNumberImpl
00023 {
00024     CPKIFNamePtr m_name;
00025     CPKIFStringPtr m_serialNumber;
00026 };
00028 
00036 CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber()
00037     :m_impl (new CPKIFIssuerAndSerialNumberImpl)
00038 {
00039     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber()", TOOLKIT_MESSAGE_ASN, 0, this);
00040 }
00049 /*CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber(
00052     CACCMSIssuerAndSerialNumber& isn)
00053     :m_impl (new CPKIFIssuerAndSerialNumberImpl)
00054 {
00055     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber(CACCMSIssuerAndSerialNumber& isn)", TOOLKIT_MESSAGE_ASN, 0, this);
00056 
00057     //throw decoder errors
00058     CPKIFNamePtr n(new CPKIFName(isn.issuer));
00059 
00060     //throw bad_alloc errors
00061     CPKIFStringPtr s(new std::string(isn.serialNumber));
00062     
00063     m_impl->m_name = n;
00064     m_impl->m_serialNumber = s;
00065 }*/
00066 
00075 CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber(
00078     const CPKIFBufferPtr& isnBuf)
00079     :m_impl (new CPKIFIssuerAndSerialNumberImpl)
00080 {
00081     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::CPKIFIssuerAndSerialNumber(CACCMSIssuerAndSerialNumber& isn)", TOOLKIT_MESSAGE_ASN, 0, this);
00082 
00083     CACASNWRAPPER_CREATE(CACCMSIssuerAndSerialNumber, isnWrapper);
00084     isnWrapper.Decode(isnBuf->GetBuffer(), isnBuf->GetLength());
00085 
00086     //throw decoder errors
00087 
00088     CACASNWRAPPER_CREATE(CACX509V3Name, objPDU);
00089     ASN1OpenType* data1 = objPDU.Encode(&(isnWrapper->issuer));
00090     CPKIFBufferPtr tmpBuf;
00091     if(data1 != NULL)
00092     {
00093          tmpBuf = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00094         delete data1;
00095     }
00096     CPKIFNamePtr n(new CPKIFName(tmpBuf));
00097     //CPKIFNamePtr n(new CPKIFName(isnWrapper->issuer));
00098 
00099     //throw bad_alloc errors
00100     CPKIFStringPtr s(new std::string(isnWrapper->serialNumber));
00101     
00102     m_impl->m_name = n;
00103     m_impl->m_serialNumber = s;
00104 }
00105 
00106 
00114 CPKIFIssuerAndSerialNumber::~CPKIFIssuerAndSerialNumber()
00115 {
00116     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::~CPKIFIssuerAndSerialNumber()", TOOLKIT_MESSAGE_ASN, 0, this);
00117 
00118     delete m_impl;
00119     m_impl = NULL;
00120 }
00130 void CPKIFIssuerAndSerialNumber::SetName(
00133     CPKIFNamePtr& name) 
00134 {
00135     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::SetName()", TOOLKIT_MESSAGE_ASN, 0, this);
00136 
00137     //accept no NULLs
00138     if(name == (CPKIFName*)NULL)
00139         throw CPKIFMessageException(TOOLKIT_MESSAGE, COMMON_INVALID_INPUT);
00140 
00141     m_impl->m_name = name;
00142 }
00150 CPKIFNamePtr CPKIFIssuerAndSerialNumber::GetName() const 
00151 {
00152     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::GetName()", TOOLKIT_MESSAGE_ASN, 0, this);
00153     return m_impl->m_name;
00154 }
00164 void CPKIFIssuerAndSerialNumber::SetSerialNumber(
00166     CPKIFStringPtr& serialNumber) 
00167 {
00168     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::SetSerialNumber()", TOOLKIT_MESSAGE_ASN, 0, this);
00169 
00170     //accept no NULLs
00171     if(serialNumber == (std::string*)NULL)
00172         throw CPKIFMessageException(TOOLKIT_MESSAGE, COMMON_INVALID_INPUT);
00173 
00174     m_impl->m_serialNumber = serialNumber;
00175 }
00183 const char* CPKIFIssuerAndSerialNumber::GetSerialNumber() const 
00184 {
00185     LOG_STRING_DEBUG("CPKIFIssuerAndSerialNumber::GetSerialNumber()", TOOLKIT_MESSAGE_ASN, 0, this);
00186 
00187     if(m_impl->m_serialNumber != (std::string*)NULL)
00188         return m_impl->m_serialNumber->c_str();
00189     else
00190         return NULL;
00191 }

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