SubjectInfoAccess.cpp

Go to the documentation of this file.
00001 
00010 #include "SubjectInfoAccess.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 CPKIFSubjectInfoAccessImpl
00028 {
00029     CPKIFAccessDescriptionListPtr m_accessDescriptions;
00030     CPKIFBufferPtr m_value;
00031     bool m_extModified;
00032 };
00033 
00035 
00036 char CPKIFSubjectInfoAccess::extOID[] =     "1.3.6.1.5.5.7.1.11";
00037 
00045 CPKIFSubjectInfoAccess::CPKIFSubjectInfoAccess()
00046 : m_impl (new CPKIFSubjectInfoAccessImpl)
00047 {
00048 }
00049 
00057 CPKIFSubjectInfoAccess::CPKIFSubjectInfoAccess(
00059     const bool& criticality,
00061     const CPKIFBufferPtr& ext) 
00062     : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFSubjectInfoAccessImpl)
00063 {
00064     CACASNWRAPPER_CREATE(CACX509V3SubjectInfoAccessSyntax, objPDU);
00065     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00066 
00067     DListNode* cur = objPDU->head;
00068     if(NULL != cur)
00069     {
00070         CPKIFAccessDescriptionListPtr adList(new CPKIFAccessDescriptionList);
00071         m_impl->m_accessDescriptions = adList;
00072     }
00073     while(NULL != cur)
00074     {
00075         
00076         ASN1OpenType* openType = (ASN1OpenType*)cur->data;
00077 
00078         CPKIFBufferPtr tmpBuffer(new CPKIFBuffer(openType->data, openType->numocts));
00079 
00080 
00081 
00082         CPKIFAccessDescriptionPtr ad(new CPKIFAccessDescription(tmpBuffer));
00083         m_impl->m_accessDescriptions->push_back(ad);
00084         cur = cur->next;
00085     }
00086 
00087     m_impl->m_value = ext;
00088     m_impl->m_extModified = false;
00089 }
00090 
00098 CPKIFSubjectInfoAccess::~CPKIFSubjectInfoAccess()
00099 {
00100     if(m_impl)
00101     {
00102         delete m_impl;
00103         m_impl = 0;
00104     }
00105 }
00114 const CPKIFOIDPtr CPKIFSubjectInfoAccess::oid() const
00115 {
00116     //added static variable for copying instead of string creation each call
00117     static CPKIFOID staticOID(extOID);
00118     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00119     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00120     return tmp;
00121 }
00129 CPKIFAccessDescriptionListPtr CPKIFSubjectInfoAccess::GetAccessDescriptions() const 
00130 {
00131     return m_impl->m_accessDescriptions;
00132 }
00140 CPKIFBufferPtr CPKIFSubjectInfoAccess::value() const 
00141 {
00142     CPKIFBufferPtr rv = m_impl->m_value;
00143     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00144     {
00145         //XXX ENCODE HERE and set rv if necessary 
00146     }
00147 
00148     return rv;
00149 }
00150 
00152 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectInfoAccessPtr & sia)
00153 {
00154     return operator<<(os,*sia);
00155 }
00156 
00158 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFSubjectInfoAccess& sia)
00159 {
00160     //get the list of access descriptions
00161     CPKIFAccessDescriptionListPtr adl = sia.GetAccessDescriptions();
00162     if(adl)
00163     {
00164         CPKIFAccessDescription ad;
00165         CPKIFAccessDescriptionList::iterator pos;
00166         CPKIFAccessDescriptionList::iterator end = adl->end();
00167         int count = 1;
00168         for(pos = adl->begin(); pos != end; ++pos)
00169         {
00170             if(count > 1) os << endl;
00171             os << "[" << count <<"]" << "Subject Info Access: " << endl;
00172             CPKIFOIDPtr accessMethod = (*pos)->AccessMethod();
00173             string accessMethodStr(accessMethod->ToString());
00174             if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.5"))
00175             {
00176                 accessMethodStr = "CA Repository (1.3.6.1.5.5.7.48.5)";
00177             }else if(0 == strcmp(accessMethod->ToString(), "1.3.6.1.5.5.7.48.3"))
00178             { 
00179                 accessMethodStr = "Timestamping Service (1.3.6.1.5.5.7.48.3)";
00180             }
00181             os << "\tAccess Method: " << accessMethodStr << endl;
00182 
00183             CPKIFGeneralNamePtr gn = (*pos)->AccessLocation();
00184             if(gn)
00185             {
00186                 os << "\tAccess Location: " << gn;
00187             } else {
00188                 os << "\tAccess Location: (null)";
00189             }
00190 
00191             count++;
00192         }
00193     }
00194 
00195     return os;
00196 }

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