00001 00009 #ifndef __HasExtensions_H__ 00010 #define __HasExtensions_H__ 00011 00012 #include "PKIFdll.h" 00013 #include <vector> 00014 00015 class IPKIFParseExtensions; 00016 FD_SMART_PTR(CPKIFBuffer); 00017 FD_SMART_PTR(CPKIFX509Extension); 00018 FD_SMART_PTR(CPKIFOID); 00019 00029 class CAC_API CAC_NO_VTABLE IPKIFHasExtensions 00030 { 00031 public: 00032 virtual ~IPKIFHasExtensions (); 00033 00034 template <typename T> boost::shared_ptr<T> GetExtension(); 00035 virtual void GetExtensions (IPKIFParseExtensions* m, std::vector<CPKIFX509ExtensionPtr>& exts); 00036 00037 virtual void GetExtensionByOID(const CPKIFOID& oid, CPKIFX509ExtensionPtr& ref) = 0; 00038 virtual void GetEncodedExtensions (CPKIFBufferPtr& buf) = 0; 00039 00040 }; 00041 DECLARE_SMART_POINTERS(IPKIFHasExtensions); 00042 00043 // needed for the template function 00044 #include "X509Extension.h" 00045 #include "OID.h" 00046 #include "ASN1Errors.h" 00047 #include "PKIFException.h" 00048 00051 00060 template <typename T> 00061 boost::shared_ptr<T> IPKIFHasExtensions::GetExtension() 00062 { 00063 CPKIFX509ExtensionPtr ext; 00064 CPKIFStringPtr oidStr(new std::string(T::extOID)); 00065 CPKIFOID oid(oidStr); 00066 GetExtensionByOID(oid,ext); 00067 00068 if(ext && 0 != dynamic_cast<T*>(ext.get())) { 00069 return *((boost::shared_ptr<T>*)&(ext)); 00070 } 00071 else if(ext) 00072 { 00073 //if we get here then an extension failed to parse 00074 throw CPKIFException(TOOLKIT_ASN, ASN1_DECODE_ERROR); 00075 } 00076 boost::shared_ptr<T> nullExt; 00077 return nullExt; 00078 } 00079 00080 #endif