AuthorityInfoAccess.cpp

Go to the documentation of this file.
00001 
00010 #include "AuthorityInfoAccess.h"
00011 #include "AccessDescription.h"
00012 #include "Buffer.h"
00013 #include "OID.h"
00014 #include "X509Extension.h"
00015 
00016 #include "ASN1Helper.h"
00017 #include "PKIX1Implicit88.h"
00018 #include "PKIX1Explicit88.h"
00019 
00020 #include <iostream>
00021 #include <sstream>
00022 
00023 using namespace std;
00024 
00026 
00027 struct CPKIFAuthorityInfoAccessImpl
00028 {
00029     CPKIFAccessDescriptionListPtr m_accessDescriptions;
00030     CPKIFBufferPtr m_value;
00031     bool m_extModified;
00032 };
00033 
00035 
00036 char CPKIFAuthorityInfoAccess::extOID[] =       "1.3.6.1.5.5.7.1.1";
00037 
00045 CPKIFAuthorityInfoAccess::CPKIFAuthorityInfoAccess()
00046 : m_impl (new CPKIFAuthorityInfoAccessImpl)
00047 {
00048 }
00059 //CPKIFAuthorityInfoAccess::CPKIFAuthorityInfoAccess(
00060 //  //! [in] An internal representation the extension in parsed form to use to construct 
00061 //  //! the CPKIFAuthorityInfoAccess object
00062 //  const CACX509V3AuthorityInfoAccessSyntax& aia)
00063 //: m_impl (new CPKIFAuthorityInfoAccessImpl)
00064 //{
00065 //  DListNode* cur = aia.head;
00066 //  if(NULL != cur)
00067 //  {
00068 //      CPKIFAccessDescriptionListPtr adList(new CPKIFAccessDescriptionList);
00069 //      m_impl->m_accessDescriptions = adList;
00070 //  }
00071 //  while(NULL != cur)
00072 //  {
00073 //      CPKIFAccessDescriptionPtr ad(new CPKIFAccessDescription((CACX509V3AccessDescription*)cur->data));
00074 //      m_impl->m_accessDescriptions->push_back(ad);
00075 //      cur = cur->next;
00076 //  }
00077 //}
00085 //CPKIFAuthorityInfoAccess::CPKIFAuthorityInfoAccess(
00086 //  //! [in] An internal representation of the extension in unparsed form to use 
00087 //  //! to construct the CPKIFAuthorityInfoAccess object
00088 //  const CACX509V3Extension& ext) 
00089 //  : CPKIFX509Extension(ext), m_impl (new CPKIFAuthorityInfoAccessImpl)
00090 //{
00091 //  CACASNWRAPPER_CREATE(CACX509V3AuthorityInfoAccessSyntax, objPDU);
00092 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00093 //
00094 //  DListNode* cur = objPDU->head;
00095 //  if(NULL != cur)
00096 //  {
00097 //      CPKIFAccessDescriptionListPtr adList(new CPKIFAccessDescriptionList);
00098 //      m_impl->m_accessDescriptions = adList;
00099 //  }
00100 //  while(NULL != cur)
00101 //  {
00102 //      CPKIFAccessDescriptionPtr ad(new CPKIFAccessDescription((CACX509V3AccessDescription*)cur->data));
00103 //      m_impl->m_accessDescriptions->push_back(ad);
00104 //      cur = cur->next;
00105 //  }
00106 //}
00107 
00115 CPKIFAuthorityInfoAccess::CPKIFAuthorityInfoAccess(
00117     const bool& criticality,
00119     const CPKIFBufferPtr& ext) 
00120     : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFAuthorityInfoAccessImpl)
00121 {
00122     CACASNWRAPPER_CREATE(CACX509V3AuthorityInfoAccessSyntax, objPDU);
00123     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00124 
00125     DListNode* cur = objPDU->head;
00126     if(NULL != cur)
00127     {
00128         CPKIFAccessDescriptionListPtr adList(new CPKIFAccessDescriptionList);
00129         m_impl->m_accessDescriptions = adList;
00130     }
00131     while(NULL != cur)
00132     {
00133         /*CACASNWRAPPER_CREATE(CACX509V3AccessDescription, objPDU);
00134         ASN1OpenType* data1 = NULL;
00135         
00136         data1 = objPDU.Encode((CACX509V3AccessDescription*)cur->data);
00137 
00138         CPKIFBufferPtr tmpBuffer(new CPKIFBuffer(data1->data, data1->numocts));
00139     
00140         if(data1)
00141         {
00142             if(data1->data)
00143                 delete data1->data;
00144             delete data1;
00145         }*/
00146         //CPKIFAccessDescriptionPtr ad(new CPKIFAccessDescription((CACX509V3AccessDescription*)cur->data));
00147 
00148         ASN1OpenType* openType = (ASN1OpenType*)cur->data;
00149 
00150         CPKIFBufferPtr tmpBuffer(new CPKIFBuffer(openType->data, openType->numocts));
00151 
00152 
00153 
00154         CPKIFAccessDescriptionPtr ad(new CPKIFAccessDescription(tmpBuffer));
00155         m_impl->m_accessDescriptions->push_back(ad);
00156         cur = cur->next;
00157     }
00158 
00159     m_impl->m_value = ext;
00160     m_impl->m_extModified = false;
00161 }
00162 
00170 CPKIFAuthorityInfoAccess::~CPKIFAuthorityInfoAccess()
00171 {
00172     if(m_impl)
00173     {
00174         delete m_impl;
00175         m_impl = 0;
00176     }
00177 }
00186 const CPKIFOIDPtr CPKIFAuthorityInfoAccess::oid() const
00187 {
00188     //added static variable for copying instead of string creation each call
00189     static CPKIFOID staticOID(extOID);
00190     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00191     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00192     return tmp;
00193 }
00201 CPKIFAccessDescriptionListPtr CPKIFAuthorityInfoAccess::GetAccessDescriptions() const 
00202 {
00203     return m_impl->m_accessDescriptions;
00204 }
00205 
00213 CPKIFBufferPtr CPKIFAuthorityInfoAccess::value() const 
00214 {
00215     CPKIFBufferPtr rv = m_impl->m_value;
00216     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00217     {
00218         //XXX ENCODE HERE and set rv if necessary 
00219     }
00220 
00221     return rv;
00222 }
00223 
00225 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFAuthorityInfoAccessPtr & aia)
00226 {
00227     return operator<<(os,*aia);
00228 }
00229 
00231 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFAuthorityInfoAccess& aia)
00232 {
00233     //get the list of access descriptions
00234     CPKIFAccessDescriptionListPtr adl = aia.GetAccessDescriptions();
00235     if(adl)
00236     {
00237         CPKIFAccessDescription ad;
00238         CPKIFAccessDescriptionList::iterator pos;
00239         CPKIFAccessDescriptionList::iterator end = adl->end();
00240         int count = 1;
00241         for(pos = adl->begin(); pos != end; ++pos)
00242         {
00243             if(count > 1) os << endl;
00244             os << "[" << count <<"]" << "Authority Info Access: " << endl;
00245             CPKIFOIDPtr accessMethod = (*pos)->AccessMethod();
00246             string accessMethodStr(accessMethod->ToString());
00247             if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.2"))
00248             {
00249                 accessMethodStr = "CA Issuer (1.3.6.1.5.5.7.48.2)";
00250             }
00251             else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.5"))
00252             {
00253                 accessMethodStr = "CA Repository (1.3.6.1.5.5.7.48.5)";
00254             }
00255             else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.1"))
00256             { 
00257                 accessMethodStr = "On-line Certificate Status Protocol (1.3.6.1.5.5.7.48.1)";
00258             }
00259 
00260             os << "\tAccess Method: " << accessMethodStr << endl;
00261 
00262             CPKIFGeneralNamePtr gn = (*pos)->AccessLocation();
00263             if(gn)
00264             {
00265                 os << "\tAccess Location: " << gn;
00266             } else {
00267                 os << "\tAccess Location: (null)";
00268             }
00269 
00270             count++;
00271         }
00272     }
00273 
00274     return os;
00275 }

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