SubjectAltName.cpp

Go to the documentation of this file.
00001 
00009 #include "SubjectAltName.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012 #include "GeneralName.h"
00013 
00014 #include "ASN1Helper.h"
00015 #include "PKIX1Implicit88.h"
00016 #include "PKIX1Explicit88.h"
00017 
00018 #include <iostream>
00019 
00021 
00022 struct CPKIFSubjectAltNameImpl
00023 {
00024     CPKIFGeneralNameList m_generalNames;
00025     CPKIFBufferPtr m_value;
00026     bool m_extModified;
00027 };
00028 
00030 
00031 char CPKIFSubjectAltName::extOID[] =            "2.5.29.17";
00032 
00033 //DOCUMENT IT LATER 
00041 CPKIFSubjectAltName::CPKIFSubjectAltName()
00042   :m_impl (new CPKIFSubjectAltNameImpl)
00043 {
00044 }
00055 //CPKIFSubjectAltName::CPKIFSubjectAltName(
00056 //  //![in] Reference to an internal structure representation of the extension containing information used to construct the object.
00057 //  const CACX509V3Extension& ext) 
00058 //  : CPKIFX509Extension(ext), m_impl (new CPKIFSubjectAltNameImpl)
00059 //{
00060 //  CACASNWRAPPER_CREATE(CACX509V3GeneralNames, objPDU);
00061 //  CACX509V3GeneralNames* gns = objPDU.Decode( ext.extnValue.data, ext.extnValue.numocts );
00062 //
00063 //  DListNode* cur = gns->head;
00064 //  for(unsigned int ii = 0; ii < gns->count; ++ii)
00065 //  {
00066 //      CPKIFGeneralNamePtr tmpGN(new CPKIFGeneralName(*(CACX509V3GeneralName*)cur->data));
00067 //      m_impl->m_generalNames.push_back(tmpGN);
00068 //
00069 //      cur = cur->next;
00070 //  }
00071 //}
00072 
00083 CPKIFSubjectAltName::CPKIFSubjectAltName(
00084     const bool& criticality,
00085     const CPKIFBufferPtr& ext) 
00086   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFSubjectAltNameImpl)
00087 {
00088     CACASNWRAPPER_CREATE(CACX509V3GeneralNames, objPDU);
00089     CACX509V3GeneralNames* gns = objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00090 
00091     DListNode* cur = gns->head;
00092     for(unsigned int ii = 0; ii < gns->count; ++ii)
00093     {
00094         //CPKIFGeneralNamePtr tmpGN(new CPKIFGeneralName(*(CACX509V3GeneralName*)cur->data));
00095         //CPKIFBufferPtr tmpBuf(new CPKIFBuffer(((ASN1OpenType*)cur->data)->data, ((ASN1OpenType*)cur->data)->numocts));
00096         //CPKIFGeneralNamePtr tmpGN(new CPKIFGeneralName(tmpBuf));
00097         CACASNWRAPPER_CREATE(CACX509V3GeneralName, objPDU);
00098         ASN1OpenType* data1 = objPDU.Encode((CACX509V3GeneralName*)cur->data);
00099         CPKIFBufferPtr tmpBuf;
00100         if (data1 != NULL)
00101         {
00102              tmpBuf = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00103             delete data1;
00104         }
00105         CPKIFGeneralNamePtr tmpGN(new CPKIFGeneralName(tmpBuf));
00106 
00107         m_impl->m_generalNames.push_back(tmpGN);
00108 
00109         cur = cur->next;
00110     }
00111 
00112     m_impl->m_value = ext;
00113     m_impl->m_extModified = false;
00114 }
00115 
00125 void CPKIFSubjectAltName::GeneralNames(
00127     CPKIFGeneralNameList& genNames) const
00128 {
00129     genNames.clear();
00130 
00131     CPKIFGeneralNameList::const_iterator pos;
00132     CPKIFGeneralNameList::const_iterator end = m_impl->m_generalNames.end();
00133     for(pos = m_impl->m_generalNames.begin(); pos != end; ++pos)
00134     {
00135         genNames.push_back(*pos);
00136     }
00137 }
00145 CPKIFSubjectAltName::~CPKIFSubjectAltName()
00146 {
00147     if(m_impl)
00148     {
00149         delete m_impl;
00150         m_impl = 0;
00151     }
00152 }
00160 const CPKIFOIDPtr CPKIFSubjectAltName::oid() const
00161 {
00162     //added static variable for copying instead of string creation each call
00163     static CPKIFOID staticOID(extOID);
00164     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00165     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00166     return tmp;
00167 }
00175 CPKIFBufferPtr CPKIFSubjectAltName::value() const 
00176 {
00177     CPKIFBufferPtr rv = m_impl->m_value;
00178     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00179     {
00180         //XXX ENCODE HERE and set rv if necessary 
00181     }
00182 
00183     return rv;
00184 }
00185 
00186 
00187 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectAltNamePtr & extension)
00188 {
00189     return operator<<(os,*extension);
00190 }
00191 
00192 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectAltName & extension)
00193 {
00194     CPKIFGeneralNames gns;
00195     try {
00196         extension.GeneralNames(gns);
00197     } catch(...) {
00198     }
00199     if(gns.size() == 0) {
00200         return os << "Unable to format CPKIFSubjectAltName.";
00201     }
00202     return os << gns;
00203 }

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