PolicyConstraints.cpp

Go to the documentation of this file.
00001 
00009 #include "PolicyConstraints.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012 
00013 #include "ASN1Helper.h"
00014 #include "PKIX1Implicit88.h"
00015 #include "PKIX1Explicit88.h"
00016 
00017 #include <iostream>
00018 using std::endl;
00019 
00021 
00022 struct CPKIFPolicyConstraintsImpl
00023 {
00024     CPKIFPolicyConstraintsImpl()
00025     {
00026         m_bRequireExplicitPolicyPresent = false;
00027         m_requireExplicitPolicy = 0;
00028         m_bInhibitPolicyMappingPresent = false;
00029         m_inhibitPolicyMapping = 0;
00030         m_extModified = false;
00031     }
00032     bool m_bRequireExplicitPolicyPresent;
00033     int m_requireExplicitPolicy;
00034     bool m_bInhibitPolicyMappingPresent;
00035     int m_inhibitPolicyMapping;
00036     CPKIFBufferPtr m_value;
00037     bool m_extModified;
00038 };
00039 
00041 
00042 char CPKIFPolicyConstraints::extOID[] =         "2.5.29.36";
00043 
00051 CPKIFPolicyConstraints::CPKIFPolicyConstraints()
00052   :m_impl (new CPKIFPolicyConstraintsImpl)
00053 {
00054 }
00065 //CPKIFPolicyConstraints::CPKIFPolicyConstraints(
00066 //  //! [in] Reference to an internal structure representation of the extension containing 
00067 //  //! information used to construct the object
00068 //  const CACX509V3Extension& ext) 
00069 //  : CPKIFX509Extension(ext), m_impl (new CPKIFPolicyConstraintsImpl)
00070 //{
00071 //  CACASNWRAPPER_CREATE(CACX509V3PolicyConstraints, objPDU);
00072 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00073 //
00074 //  if(objPDU->m.inhibitPolicyMappingPresent)
00075 //  {
00076 //      m_impl->m_bInhibitPolicyMappingPresent = true;
00077 //      m_impl->m_inhibitPolicyMapping = objPDU->inhibitPolicyMapping;
00078 //  }
00079 //  else
00080 //      m_impl->m_bInhibitPolicyMappingPresent = false;
00081 //
00082 //  if(objPDU->m.requireExplicitPolicyPresent)
00083 //  {
00084 //      m_impl->m_bRequireExplicitPolicyPresent = true;
00085 //      m_impl->m_requireExplicitPolicy = objPDU->requireExplicitPolicy;
00086 //  }
00087 //  else
00088 //      m_impl->m_bRequireExplicitPolicyPresent = false;
00089 //}
00090 
00101 CPKIFPolicyConstraints::CPKIFPolicyConstraints(
00102     const bool& criticality,
00103     const CPKIFBufferPtr& ext) 
00104   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFPolicyConstraintsImpl)
00105 {
00106     CACASNWRAPPER_CREATE(CACX509V3PolicyConstraints, objPDU);
00107     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00108 
00109     if(objPDU->m.inhibitPolicyMappingPresent)
00110     {
00111         m_impl->m_bInhibitPolicyMappingPresent = true;
00112         m_impl->m_inhibitPolicyMapping = objPDU->inhibitPolicyMapping;
00113     }
00114     else
00115         m_impl->m_bInhibitPolicyMappingPresent = false;
00116 
00117     if(objPDU->m.requireExplicitPolicyPresent)
00118     {
00119         m_impl->m_bRequireExplicitPolicyPresent = true;
00120         m_impl->m_requireExplicitPolicy = objPDU->requireExplicitPolicy;
00121     }
00122     else
00123         m_impl->m_bRequireExplicitPolicyPresent = false;
00124 
00125     m_impl->m_value = ext;
00126     m_impl->m_extModified = false;
00127 }
00128 
00129 
00137 CPKIFPolicyConstraints::~CPKIFPolicyConstraints()
00138 {
00139     if(m_impl)
00140     {
00141         delete m_impl;
00142         m_impl = 0;
00143     }
00144 }
00153 bool CPKIFPolicyConstraints::RequireExplicitPolicyPresent() const 
00154 {
00155     return m_impl->m_bRequireExplicitPolicyPresent;
00156 }
00165 void CPKIFPolicyConstraints::SetRequireExplicitPolicyPresent(bool b)
00166 {
00167     m_impl->m_bRequireExplicitPolicyPresent = b;
00168     m_impl->m_extModified = true;
00169 }
00170 // THIS FUNCTION IS RETURNING AN INT
00171 // TO DO
00179 int CPKIFPolicyConstraints::RequireExplicitPolicy() const 
00180 {
00181     return m_impl->m_requireExplicitPolicy;
00182 }
00183 
00191 void CPKIFPolicyConstraints::SetRequireExplicitPolicy(int skipCerts)
00192 {
00193     SetRequireExplicitPolicyPresent(true);
00194     m_impl->m_requireExplicitPolicy = skipCerts;
00195     m_impl->m_extModified = true;
00196 }
00205 bool CPKIFPolicyConstraints::InhibitPolicyMappingPresent() const 
00206 {
00207     return m_impl->m_bInhibitPolicyMappingPresent;
00208 }
00217 void CPKIFPolicyConstraints::SetInhibitPolicyMappingPresent(bool b)
00218 {
00219     m_impl->m_bInhibitPolicyMappingPresent = b;
00220     m_impl->m_extModified = true;
00221 }
00222 // TO DO 
00223 // THIS FUNCTION IS RETURNING AN INT 
00231 int CPKIFPolicyConstraints::InhibitPolicyMapping() const 
00232 {
00233     return m_impl->m_inhibitPolicyMapping;
00234 }
00242 void CPKIFPolicyConstraints::SetInhibitPolicyMapping(int skipCerts)
00243 {
00244     SetInhibitPolicyMappingPresent(true);
00245     m_impl->m_inhibitPolicyMapping = skipCerts;
00246     m_impl->m_extModified = true;
00247 }
00256 const CPKIFOIDPtr CPKIFPolicyConstraints::oid() const
00257 {
00258     //added static variable for copying instead of string creation each call
00259     static CPKIFOID staticOID(extOID);
00260     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00261     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00262     return tmp;
00263 }
00264 
00272 CPKIFBufferPtr CPKIFPolicyConstraints::value() const 
00273 {
00274     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00275     {
00276         CACASNWRAPPER_CREATE(CACX509V3PolicyConstraints, objPDU);   
00277         CACX509V3PolicyConstraints ext;
00278         memset(&ext, 0, sizeof(CACX509V3PolicyConstraints));
00279         if (RequireExplicitPolicyPresent())
00280         {
00281             ext.m.requireExplicitPolicyPresent = 1;
00282             ext.requireExplicitPolicy = RequireExplicitPolicy();
00283         }
00284         if (InhibitPolicyMappingPresent())
00285         {
00286             ext.m.inhibitPolicyMappingPresent = 1;
00287             ext.inhibitPolicyMapping = InhibitPolicyMapping();
00288         }
00289 
00290         ASN1OpenType* extEncoded = NULL;
00291         extEncoded = objPDU.Encode(&ext);
00292 
00293         CPKIFBufferPtr tmp(new CPKIFBuffer(extEncoded->data, extEncoded->numocts));
00294         
00295         m_impl->m_value = tmp;
00296         m_impl->m_extModified = false;
00297         if(extEncoded)
00298             delete extEncoded;
00299     }
00300 
00301     return m_impl->m_value;
00302 }
00303 
00304 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFPolicyConstraintsPtr & extension)
00305 {
00306     return operator<<(os,*extension);
00307 }
00308 
00309 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFPolicyConstraints & extension)
00310 {
00311     bool output = false;
00312     if(extension.InhibitPolicyMappingPresent())
00313     {
00314         int inhPolMap = extension.InhibitPolicyMapping();
00315         os << "Inhibit Policy Mapping Skip Certs=" <<inhPolMap;
00316         output = true;
00317     }
00318     if(extension.RequireExplicitPolicyPresent())
00319     {
00320         int rep = extension.RequireExplicitPolicy();
00321         if(output) os << endl;
00322         os << "Require Explicit Policy Skip Certs=" <<rep;
00323     }
00324     return os;
00325 }

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