AlgorithmIdentifier.cpp

Go to the documentation of this file.
00001 
00009 #include "AlgorithmIdentifier.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012 #include "ASN1Helper.h"
00013 
00014 #include "PKIX1Implicit88.h"
00015 #include "PKIX1Explicit88.h"
00016 
00018 
00019 struct CPKIFAlgorithmIdentifierImpl
00020 {
00022     CPKIFOIDPtr m_algorithm;
00023 
00024     CPKIFBufferPtr m_parametersBuf;
00025 
00027     ASN1OpenType*  m_parameters;
00028 };
00029 
00031 
00042 CPKIFAlgorithmIdentifier::CPKIFAlgorithmIdentifier()
00043 : m_impl (new CPKIFAlgorithmIdentifierImpl)
00044 {
00045     m_impl->m_parameters = NULL;
00046 }
00047 
00058 CPKIFAlgorithmIdentifier::CPKIFAlgorithmIdentifier(
00060     const CPKIFOIDPtr &oid,
00062     const CPKIFBufferPtr& params)
00063 : m_impl (new CPKIFAlgorithmIdentifierImpl)
00064 {
00065     CPKIFOIDPtr tmp(new CPKIFOID((std::string(oid->ToString()))));
00066     m_impl->m_algorithm = tmp;
00067     if(params)
00068     {
00069         m_impl->m_parameters = new ASN1OpenType;
00070         m_impl->m_parameters->data = new unsigned char[params->GetLength()];
00071         memcpy((void*)m_impl->m_parameters->data, params->GetBuffer(), params->GetLength());
00072         m_impl->m_parameters->numocts = params->GetLength();
00073     }
00074     else
00075         m_impl->m_parameters = NULL;
00076 }
00077 
00088 CPKIFAlgorithmIdentifier::CPKIFAlgorithmIdentifier(
00090     const CPKIFOIDPtr& oid) 
00091 : m_impl (new CPKIFAlgorithmIdentifierImpl)
00092 {
00093     m_impl->m_algorithm = oid; m_impl->m_parameters = NULL;
00094 }
00102 CPKIFAlgorithmIdentifier::CPKIFAlgorithmIdentifier(
00104     const CPKIFAlgorithmIdentifier& alg)
00105 : m_impl (new CPKIFAlgorithmIdentifierImpl)
00106 {
00107     CPKIFOIDPtr tmp(new CPKIFOID((std::string(alg.m_impl->m_algorithm->ToString()))));
00108     m_impl->m_algorithm = tmp;
00109     if( alg.m_impl->m_parameters )
00110     {
00111         m_impl->m_parameters = new ASN1OpenType;
00112         m_impl->m_parameters->data = new unsigned char[alg.m_impl->m_parameters->numocts];
00113         memcpy((void*)m_impl->m_parameters->data, alg.m_impl->m_parameters->data, alg.m_impl->m_parameters->numocts);
00114         m_impl->m_parameters->numocts = alg.m_impl->m_parameters->numocts;
00115     }
00116     else
00117         m_impl->m_parameters = NULL;
00118 }
00119 
00127 CPKIFAlgorithmIdentifier::~CPKIFAlgorithmIdentifier()
00128 {
00129     if(m_impl)
00130     {
00131         if(NULL != m_impl->m_parameters)
00132         {
00133             if(NULL != m_impl->m_parameters->data)
00134             {
00135                 delete[] m_impl->m_parameters->data; m_impl->m_parameters->data = NULL;
00136             }
00137 
00138             delete m_impl->m_parameters; m_impl->m_parameters = NULL;
00139         }
00140 
00141         delete m_impl;
00142         m_impl = 0;
00143     }
00144 }
00145 
00154 CPKIFOIDPtr CPKIFAlgorithmIdentifier::oid() const 
00155 {
00156     return m_impl->m_algorithm;
00157 }
00158 
00166 bool CPKIFAlgorithmIdentifier::hasParameters() const 
00167 {
00168     return NULL != m_impl->m_parameters;
00169 }
00170 
00181 bool CPKIFAlgorithmIdentifier::operator==(
00183     const CPKIFAlgorithmIdentifier& rhs) const 
00184 {
00185     return *m_impl->m_algorithm == *rhs.m_impl->m_algorithm;
00186 }
00187 
00198 CPKIFBufferPtr CPKIFAlgorithmIdentifier::parameters() const
00199 {
00200     if(hasParameters() && !m_impl->m_parametersBuf)
00201     {
00202         CPKIFBufferPtr tmp(new CPKIFBuffer(m_impl->m_parameters->data, m_impl->m_parameters->numocts));
00203         m_impl->m_parametersBuf = tmp;
00204         return m_impl->m_parametersBuf;
00205     }
00206     else if(hasParameters())
00207     {
00208         return m_impl->m_parametersBuf;
00209     }
00210     else
00211     {
00212         CPKIFBufferPtr tmp;
00213         m_impl->m_parametersBuf = tmp;
00214         return m_impl->m_parametersBuf;
00215     }
00216 }
00217 

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