BasicConstraints.cpp

Go to the documentation of this file.
00001 
00009 #include "BasicConstraints.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 CPKIFBasicConstraintsImpl
00023 {
00024     bool m_isCA;
00025     int m_pathLength;
00026     bool m_pathLengthPresent;
00027     CPKIFBufferPtr m_value;
00028     bool m_extModified;
00029 };
00030 
00032 
00033 char CPKIFBasicConstraints::extOID[] =          "2.5.29.19";
00034 
00035 /*
00036 const char* CPKIFBasicConstraintsFactory::refOID()
00037 {
00038     return CPKIFBasicConstraints::extOID;
00039 }
00040 */
00041 
00049 CPKIFBasicConstraints::CPKIFBasicConstraints()
00050 :m_impl(new CPKIFBasicConstraintsImpl)
00051 {
00052     m_impl->m_isCA = false;
00053     m_impl->m_pathLengthPresent = false;
00054     m_impl->m_pathLength = 0;
00055 }
00068 //CPKIFBasicConstraints::CPKIFBasicConstraints(
00069 //  //! [in] Reference to an internal structure representation of the extension containing 
00070 //  //! information used to construct the object
00071 //    const CACX509V3Extension& ext) 
00072 //  : CPKIFX509Extension(ext), m_impl (new CPKIFBasicConstraintsImpl)
00073 //{
00074 //  CACASNWRAPPER_CREATE(CACX509V3BasicConstraints, objPDU);
00075 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00076 //
00077 //  m_impl->m_isCA = FALSE == objPDU->cA ? false : true;
00078 //  m_impl->m_pathLengthPresent = objPDU->m.pathLenConstraintPresent;
00079 //  if(m_impl->m_pathLengthPresent)
00080 //      m_impl->m_pathLength = objPDU->pathLenConstraint;
00081 //  else
00082 //      m_impl->m_pathLength = 0;
00083 //}
00084 
00096 CPKIFBasicConstraints::CPKIFBasicConstraints(const bool& criticality, const CPKIFBufferPtr& ext)
00097   :CPKIFX509Extension (criticality, ext), m_impl (new CPKIFBasicConstraintsImpl)
00098 {
00099     CACASNWRAPPER_CREATE(CACX509V3BasicConstraints, objPDU);
00100     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00101 
00102     m_impl->m_isCA = FALSE == objPDU->cA ? false : true;
00103     m_impl->m_pathLengthPresent = objPDU->m.pathLenConstraintPresent;
00104     if(m_impl->m_pathLengthPresent)
00105         m_impl->m_pathLength = objPDU->pathLenConstraint;
00106     else
00107         m_impl->m_pathLength = 0;
00108 
00109     m_impl->m_value = ext;
00110     m_impl->m_extModified = false;
00111 }
00112 
00120 CPKIFBasicConstraints::~CPKIFBasicConstraints()
00121 {
00122     if(0 != m_impl) {
00123         delete m_impl;
00124         m_impl = 0;
00125     }
00126 }
00127 //commented out 8/21/2004
00128 //CPKIFBasicConstraints::CPKIFBasicConstraints(const CPKIFBasicConstraints& ext) 
00129 //{
00130 //}
00131 
00139 bool CPKIFBasicConstraints::pathLengthPresent() const 
00140 {
00141     return m_impl->m_pathLengthPresent;
00142 }
00151 bool CPKIFBasicConstraints::isCA() const
00152 {
00153     return m_impl->m_isCA;
00154 }
00155 
00164 int CPKIFBasicConstraints::pathLength() const
00165 {
00166     return m_impl->m_pathLength;
00167 }
00168 
00176 const CPKIFOIDPtr CPKIFBasicConstraints::oid() const
00177 {
00178     //added static variable for copying instead of string creation each call
00179     static CPKIFOID staticOID(extOID);
00180     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00181     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00182     return tmp;
00183 }
00184 
00192 CPKIFBufferPtr CPKIFBasicConstraints::value() const 
00193 {
00194     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00195     {
00196         CACASNWRAPPER_CREATE(CACX509V3BasicConstraints, objPDU);    
00197         CACX509V3BasicConstraints ext;
00198         memset(&ext, 0, sizeof(CACX509V3BasicConstraints));
00199         if (pathLengthPresent())
00200         {
00201             ext.m.pathLenConstraintPresent = 1;
00202             ext.pathLenConstraint = pathLength();
00203         }
00204         ext.cA = isCA();
00205 
00206         ASN1OpenType* extEncoded = NULL;
00207         extEncoded = objPDU.Encode(&ext);
00208 
00209         CPKIFBufferPtr tmp(new CPKIFBuffer(extEncoded->data, extEncoded->numocts));
00210         
00211         m_impl->m_value = tmp;
00212         m_impl->m_extModified = false;
00213         if(extEncoded)
00214             delete extEncoded;
00215     }
00216 
00217     return m_impl->m_value;
00218 }
00219 
00220 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFBasicConstraintsPtr & extension)
00221 {
00222     return operator<<(os,*extension);
00223 }
00224 
00225 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFBasicConstraints & extension)
00226 {
00227     if(extension.isCA())
00228     {
00229         os << "Subject type: CA";
00230     } else {
00231         os << "Subject type: EE";
00232     }
00233     if(extension.pathLengthPresent())
00234     {
00235         os << ", Path length constraint=" << extension.pathLength();
00236     }
00237     return os;
00238 }
00239 
00240 void CPKIFBasicConstraints::SetIsCA(bool b)
00241 {
00242     m_impl->m_isCA = b;
00243     m_impl->m_extModified = true;
00244 }
00245 
00246 void CPKIFBasicConstraints::SetPathLength(int pl)
00247 {
00248     m_impl->m_pathLength = pl;
00249     if(-1 != pl)
00250         m_impl->m_pathLengthPresent = true;
00251     else
00252         m_impl->m_pathLengthPresent = false;
00253     m_impl->m_extModified = true;
00254 }

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