InhibitAnyPolicy.cpp

Go to the documentation of this file.
00001 
00009 #include "InhibitAnyPolicy.h"
00010 #include "OID.h"
00011 #include "Buffer.h"
00012 
00013 #include "ASN1Helper.h"
00014 #include "PKIX1Implicit88.h"
00015 #include "PKIX1Explicit88.h"
00016 
00017 
00018 #include <iostream>
00019 
00021 
00022 struct CPKIFInhibitAnyPolicyImpl
00023 {
00024     int m_skipCerts;
00025     CPKIFBufferPtr m_value;
00026     bool m_extModified;
00027 };
00028 
00030 
00031 char CPKIFInhibitAnyPolicy::extOID[] =          "2.5.29.54";
00032 
00040 CPKIFInhibitAnyPolicy::CPKIFInhibitAnyPolicy()
00041   :m_impl (new CPKIFInhibitAnyPolicyImpl)
00042 {
00043 }
00054 //CPKIFInhibitAnyPolicy::CPKIFInhibitAnyPolicy(
00055 //  //! [in] Reference to an internal structure representation of the extension containing 
00056 //  //! information used to construct the object
00057 //  const CACX509V3Extension& ext) 
00058 //  : CPKIFX509Extension(ext), m_impl (new CPKIFInhibitAnyPolicyImpl)
00059 //{
00060 //  CACASNWRAPPER_CREATE(CACX509V3SkipCerts, objPDU);
00061 //  objPDU.Decode(ext.extnValue.data, ext.extnValue.numocts);
00062 //  
00063 //  CACX509V3SkipCerts* tmp = objPDU.data();
00064 //  if(NULL != tmp)
00065 //      m_impl->m_skipCerts = *tmp;
00066 //}
00067 
00078 CPKIFInhibitAnyPolicy::CPKIFInhibitAnyPolicy(
00079     const bool& criticality,
00080     const CPKIFBufferPtr& ext) 
00081   : CPKIFX509Extension (criticality, ext), m_impl (new CPKIFInhibitAnyPolicyImpl)
00082 {
00083     CACASNWRAPPER_CREATE(CACX509V3SkipCerts, objPDU);
00084     objPDU.Decode(ext->GetBuffer(), ext->GetLength());
00085     
00086     CACX509V3SkipCerts* tmp = objPDU.data();
00087     if(NULL != tmp)
00088         m_impl->m_skipCerts = *tmp;
00089 
00090     m_impl->m_value = ext;
00091     m_impl->m_extModified = false;
00092 }
00093 
00101 CPKIFInhibitAnyPolicy::~CPKIFInhibitAnyPolicy()
00102 {
00103     if(m_impl)
00104     {
00105         delete m_impl;
00106         m_impl = 0;
00107     }
00108 }
00117 const CPKIFOIDPtr CPKIFInhibitAnyPolicy::oid() const
00118 {
00119     //added static variable for copying instead of string creation each call
00120     static CPKIFOID staticOID(extOID);
00121     //CPKIFOIDPtr tmp(new CPKIFOID(new std::string(extOID)));
00122     static CPKIFOIDPtr tmp(new CPKIFOID(staticOID));
00123     return tmp;
00124 }
00132 int CPKIFInhibitAnyPolicy::SkipCerts()
00133 {
00134     return m_impl->m_skipCerts;
00135 }
00143 void CPKIFInhibitAnyPolicy::SetSkipCerts(int skipCerts)
00144 {
00145     m_impl->m_skipCerts = skipCerts;
00146     m_impl->m_extModified = true;
00147 }
00155 CPKIFBufferPtr CPKIFInhibitAnyPolicy::value() const 
00156 {
00157     if(m_impl->m_value == (CPKIFBuffer*)NULL || m_impl->m_extModified)
00158     {
00159         CACASNWRAPPER_CREATE(CACX509V3InhibitAnyPolicy, objPDU);    
00160         CACX509V3InhibitAnyPolicy ext;
00161         memset(&ext, 0, sizeof(CACX509V3InhibitAnyPolicy));
00162 
00163         ext = m_impl->m_skipCerts;
00164 
00165         ASN1OpenType* extEncoded = NULL;
00166         extEncoded = objPDU.Encode(&ext);
00167 
00168         CPKIFBufferPtr tmp(new CPKIFBuffer(extEncoded->data, extEncoded->numocts));
00169         
00170         m_impl->m_value = tmp;
00171         m_impl->m_extModified = false;
00172         if(extEncoded)
00173             delete extEncoded;
00174     }
00175 
00176     return m_impl->m_value;
00177 }
00178 
00179 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFInhibitAnyPolicyPtr & extension)
00180 {
00181     return operator<<(os,*extension);
00182 }
00183 
00184 CAC_API std::ostream& operator<<(std::ostream & os, const CPKIFInhibitAnyPolicy & extension)
00185 {
00186     // const_cast is OK here. that getter should really be const.
00187     return os << "Inhibit Any-policy (skip certs= " << const_cast<CPKIFInhibitAnyPolicy &>(extension).SkipCerts() << ")";
00188 }
00189 

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