Buffer.cpp

Go to the documentation of this file.
00001 
00009 #include "Buffer.h"
00010 #include "ooasn1.h"
00011 
00012 using namespace std;
00013 
00015 
00016 struct CPKIFBufferImpl
00017 {
00018     unsigned char* m_buf;
00019     unsigned int m_bufLen;
00020 };
00021 
00023 
00040 CPKIFBuffer::CPKIFBuffer()
00041   :m_impl (new CPKIFBufferImpl)
00042 {
00043     m_impl->m_buf = NULL;
00044     m_impl->m_bufLen = 0;
00045 }
00046 
00063 CPKIFBuffer::CPKIFBuffer(
00065     bool takeOwnership,
00067     unsigned char* buf, 
00069     unsigned int bufLen)
00070   :m_impl (new CPKIFBufferImpl)
00071 {
00072     if(NULL == buf || 0 == bufLen)
00073     {
00074         m_impl->m_buf = NULL;
00075         m_impl->m_bufLen = 0;
00076         return;
00077     }
00078 
00079     if(!takeOwnership)
00080     {
00081         m_impl->m_buf = new unsigned char[bufLen + 1];
00082         m_impl->m_bufLen = bufLen;
00083         memcpy(m_impl->m_buf, buf, bufLen);
00084         m_impl->m_buf[bufLen] = 0x00;
00085     }
00086     else
00087     {
00088         m_impl->m_buf = buf;
00089         m_impl->m_bufLen = bufLen;
00090     }
00091 }
00092 
00110 CPKIFBuffer::CPKIFBuffer(
00112     const unsigned char* buf, 
00114     unsigned int bufLen)
00115 :m_impl (new CPKIFBufferImpl)
00116 {
00117     if(NULL == buf || 0 == bufLen)
00118     {
00119         m_impl->m_buf = NULL;
00120         m_impl->m_bufLen = 0;
00121         return;
00122     }
00123 
00124     m_impl->m_buf = new unsigned char[bufLen+1];
00125     m_impl->m_bufLen = bufLen;
00126     memcpy(m_impl->m_buf, buf, bufLen);
00127     m_impl->m_buf[bufLen] = 0x00;
00128 }
00129 
00147 CPKIFBuffer::CPKIFBuffer(
00149     const CPKIFBuffer& data)
00150   :m_impl (new CPKIFBufferImpl)
00151 {
00152     if(NULL == data.m_impl->m_buf || 0 == data.m_impl->m_bufLen)
00153     {
00154         m_impl->m_buf = NULL;
00155         m_impl->m_bufLen = 0;
00156         return;
00157     }
00158 
00159     m_impl->m_buf = new unsigned char[data.m_impl->m_bufLen];
00160     m_impl->m_bufLen = data.m_impl->m_bufLen;
00161     memcpy(m_impl->m_buf, data.m_impl->m_buf, data.m_impl->m_bufLen);
00162 }
00163 
00171 CPKIFBuffer::~CPKIFBuffer()
00172 {
00173     if(m_impl)
00174     {
00175         if(NULL != m_impl->m_buf)
00176         {
00177             delete[] m_impl->m_buf; m_impl->m_buf = NULL;
00178         }
00179 
00180         delete m_impl;
00181         m_impl = 0;
00182     }
00183 }
00184 
00193 const unsigned char* CPKIFBuffer::GetBuffer() const 
00194 {
00195     return m_impl->m_buf;
00196 }
00204 unsigned int CPKIFBuffer::GetLength() const 
00205 {
00206     return m_impl->m_bufLen;
00207 }
00208 
00218 bool CPKIFBuffer::operator==(
00220                              const CPKIFBuffer& rhs)
00221 {
00222     if(m_impl->m_bufLen != rhs.m_impl->m_bufLen)
00223         return false;
00224 
00226     if(0 == m_impl->m_bufLen)
00227         return true; 
00228 
00229     return 0 == memcmp(m_impl->m_buf, rhs.m_impl->m_buf, m_impl->m_bufLen);
00230 }
00231 
00240 bool CPKIFBuffer::operator!=(
00242                              const CPKIFBuffer& rhs)
00243 {
00244     return !this->operator ==(rhs);
00245 }
00246 
00248 
00260 unsigned char* CPKIFBuffer::AllocateBuffer(
00262                             int len)
00263 {
00264     if(NULL != m_impl->m_buf)
00265     {
00266         delete[] m_impl->m_buf; m_impl->m_buf = NULL;
00267     }
00268 
00269     m_impl->m_buf = new unsigned char[len];
00270     m_impl->m_bufLen = len;
00271 
00272     return m_impl->m_buf;
00273 }

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