PolicyMappings.cpp

Go to the documentation of this file.
00001 
00009 #include "PolicyMappings.h"
00010 #include "PolicyMapping.h"
00011 #include "OID.h"
00012 #include "Buffer.h"
00013 
00014 #include "ASN1Helper.h"
00015 #include "PKIX1Implicit88.h"
00016 #include "PKIX1Explicit88.h"
00017 
00018 #include <iostream>
00019 using std::endl;
00020 
00022 
00023 struct CPKIFPolicyMappingsImpl 
00024 {
00025     CPKIFPolicyMappingListPtr m_policyMappingList;
00026     CPKIFBufferPtr m_value;
00027     bool m_extModified;
00028 };
00029 
00031 
00032 char CPKIFPolicyMappings::extOID[] =            "2.5.29.33";
00033 
00041 CPKIFPolicyMappings::CPKIFPolicyMappings()
00042   :m_impl (new CPKIFPolicyMappingsImpl)
00043 {
00044 }
00055 //CPKIFPolicyMappings::CPKIFPolicyMappings(
00056 //  //! [in] Reference to an internal structure representation of the extension containing 
00057 //  //! information used to construct the object
00058 //  const CACX509V3Extension& ext) 
00059 //  : CPKIFX509Extension(ext), m_impl (new CPKIFPolicyMappingsImpl)
00060 //{
00061 //  CACASNWRAPPER_CREATE(CACX509V3PolicyMappings, objPDU);
00062 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00063 //
00064 //  DListNode* cur = objPDU->head;
00065 //  if(NULL != cur)
00066 //  {
00067 //      CPKIFPolicyMappingListPtr piList(new CPKIFPolicyMappingList);
00068 //      m_impl->m_policyMappingList = piList;
00069 //  }
00070 //  while(NULL != cur)
00071 //  {
00072 //      CPKIFPolicyMappingPtr pi(new CPKIFPolicyMapping((CACX509V3PolicyMappings_element*)cur->data));
00073 //      m_impl->m_policyMappingList->push_back(pi);
00074 //      cur = cur->next;
00075 //  }
00076 //}
00077 
00088 CPKIFPolicyMappings::CPKIFPolicyMappings(
00089     const bool& criticality,
00090     const CPKIFBufferPtr& ext) 
00091   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFPolicyMappingsImpl)
00092 {
00093     CACASNWRAPPER_CREATE(CACX509V3PolicyMappings, objPDU);
00094     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00095 
00096     DListNode* cur = objPDU->head;
00097     if(NULL != cur)
00098     {
00099         CPKIFPolicyMappingListPtr piList(new CPKIFPolicyMappingList);
00100         m_impl->m_policyMappingList = piList;
00101     }
00102     while(NULL != cur)
00103     {
00104         CPKIFOID issuerDomainPolicy(((CACX509V3PolicyMappings_element*)cur->data)->issuerDomainPolicy.subid, 
00105             ((CACX509V3PolicyMappings_element*)cur->data)->issuerDomainPolicy.numids);
00106         CPKIFOID subjectDomainPolicy(((CACX509V3PolicyMappings_element*)cur->data)->subjectDomainPolicy.subid, 
00107             ((CACX509V3PolicyMappings_element*)cur->data)->subjectDomainPolicy.numids);
00108         //CPKIFPolicyMappingPtr pi(new CPKIFPolicyMapping((CACX509V3PolicyMappings_element*)cur->data));
00109         CPKIFPolicyMappingPtr pi(new CPKIFPolicyMapping(issuerDomainPolicy, subjectDomainPolicy));
00110         m_impl->m_policyMappingList->push_back(pi);
00111         cur = cur->next;
00112     }
00113 
00114     m_impl->m_value = ext;
00115     m_impl->m_extModified = false;
00116 }
00117 
00125 CPKIFPolicyMappingListPtr CPKIFPolicyMappings::PolicyMappings() const 
00126 {
00127     return m_impl->m_policyMappingList;
00128 }
00136 CPKIFPolicyMappings::~CPKIFPolicyMappings()
00137 {
00138     if(m_impl)
00139     {
00140         delete m_impl;
00141         m_impl = 0;
00142     }
00143 }
00152 const CPKIFOIDPtr CPKIFPolicyMappings::oid() const
00153 {
00154     //added static variable for copying instead of string creation each call
00155     static CPKIFOID staticOID(extOID);
00156     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00157     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00158     return tmp;
00159 }
00167 CPKIFBufferPtr CPKIFPolicyMappings::value() const 
00168 {
00169     CPKIFBufferPtr rv = m_impl->m_value;
00170     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00171     {
00172         //XXX ENCODE HERE and set rv if necessary 
00173     }
00174 
00175     return rv;
00176 }
00177 
00178 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFPolicyMappingsPtr & extension)
00179 {
00180     return operator<<(os,*extension);
00181 }
00182 
00183 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFPolicyMappings & extension)
00184 {
00185     CPKIFPolicyMappingListPtr polMapping = extension.PolicyMappings();
00186 
00187     CPKIFPolicyMappingList::iterator pos;
00188     CPKIFPolicyMappingList::iterator end = polMapping->end();
00189     int count = 1;
00190     for(pos = polMapping->begin(); pos != end; ++pos)
00191     {
00192         if(count > 1) os << endl;
00193         os << "[" << count << "]" << "Issuer Domain=" <<(*pos)->IssuerDomain()->ToString()
00194             << ", Subject Domain=" <<(*pos)->SubjectDomain()->ToString();
00195         count++;
00196     }
00197     return os;
00198 }

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