SignerInfo.h

Go to the documentation of this file.
00001 
00009 #ifndef __SIGNERINFO_H__
00010 #define __SIGNERINFO_H__
00011 
00012 #include "PKIFCMSDLL.h"
00013 #include "IPKIFHasAttributes.h"
00014 #include "OID.h"
00015 
00016 #include <vector>
00017 
00018 FD_SMART_PTR(CPKIFIssuerAndSerialNumber);
00019 FD_LIST_PTR(CPKIFAttribute);
00020 FD_SMART_PTR(CPKIFCredential);
00021 FD_SMART_PTR(CPKIFAlgorithmIdentifier);
00022 
00039 class PKIFCMS_API CPKIFSignerInfo : public IPKIFHasAttributes
00040 {
00041 public:
00042     CPKIFSignerInfo();
00043     CPKIFSignerInfo(const CPKIFBufferPtr& siBuf);
00044     virtual ~CPKIFSignerInfo();
00045 
00046     //Get/SetCredential are only used when generating a message.  When parsing a message
00047     //these functions are not used and GetCredential will always return a pointer to NULL.
00048     void SetCredential(CPKIFCredentialPtr& cred, bool enforceKeyUsage = true);
00049     CPKIFCredentialPtr GetCredential() const;
00050 
00051     bool Decoded() const;
00052 
00053     //version
00054     //CACCMSCMSVersion Version();
00055     unsigned int Version();
00056 
00057     //signer identifier (encapsulated by this class rather than in its own class)
00058     enum SignerIdentifierChoice {ISSUERANDSERIAL, SKID, UNSET};
00059     SignerIdentifierChoice GetSignerIdentifierChoice() const;
00060 
00061     void SetIssuerAndSerialNumber(CPKIFIssuerAndSerialNumberPtr& iasn);
00062     CPKIFIssuerAndSerialNumberPtr GetIssuerAndSerialNumber() const;
00063 
00064     void SetSKID(CPKIFBufferPtr& skid);
00065     CPKIFBufferPtr GetSKID() const;
00066 
00067     //digest alg
00068     CPKIFAlgorithmIdentifierPtr GetDigestAlg() const;
00069     void SetDigestAlg(CPKIFAlgorithmIdentifierPtr& digAlg);
00070 
00071     //signed attrs
00072     void GetSignedAttributes(CPKIFAttributeList& sal);
00073     void AddSignedAttribute(CPKIFAttributePtr& sa);
00074     template <class T> boost::shared_ptr<T> GetSignedAttribute();
00075 
00076     //signature alg
00077     CPKIFAlgorithmIdentifierPtr GetSignatureAlgorithm() const;
00078 
00079     //signature
00080     CPKIFBufferPtr GetSignature() const;
00081 
00082     //unsigned attrs
00083     void GetUnsignedAttributes(CPKIFAttributeList& ual);
00084     void AddUnsignedAttribute(CPKIFAttributePtr& ua);
00085 
00086     // The following 2 functions are declared virtual in "IPKIFHasAttributes"
00087     void GetEncodedSignedAttributes (CPKIFBufferPtr& buf);
00088     void GetEncodedUnsignedAttributes (CPKIFBufferPtr& buf);
00089 
00090     template <class T> boost::shared_ptr<T> GetUnsignedAttribute();
00091 
00092     // The following functions are a workaround bc it's not wise to use
00093     // static members inside of template functions.  This should be revisited
00094     // after a more "correct" approach has been decided.
00095     void _GetSignedAttributes(std::vector<CPKIFAttributePtr>& attrVector);
00096     void _GetUnsignedAttributes(std::vector<CPKIFAttributePtr>& attrVector);
00097 
00098     virtual void GetAddedSignedAttributes(std::vector<CPKIFAttributePtr>& attr);
00099     virtual void GetAddedUnsignedAttributes(std::vector<CPKIFAttributePtr>& attr);
00100 private:
00102     CPKIFSignerInfo(const CPKIFSignerInfo& copy);
00104     CPKIFSignerInfo& operator=(const CPKIFSignerInfo& rhs); //added 4/6/2004
00105 
00106     struct CPKIFSignerInfoImpl *m_impl;
00107 
00108 };
00109 DECLARE_SMART_POINTERS(CPKIFSignerInfo);
00110 typedef std::vector<CPKIFSignerInfoPtr, PKIFAlloc<CPKIFSignerInfoPtr> > CPKIFSignerInfoList;
00111 DECLARE_SMART_POINTERS(CPKIFSignerInfoList);
00112 // compatibility typedef for applications
00113 typedef CPKIFSignerInfoList CPKIFSignerInfos;
00114 DECLARE_SMART_POINTERS(CPKIFSignerInfos);
00115 
00123 template <class T> boost::shared_ptr<T> CPKIFSignerInfo::GetUnsignedAttribute()
00124 {
00125   //XXX*** Read the comments below and fix this please 
00126   
00127   std::vector<CPKIFAttributePtr> attrVector;
00128   // The following function is a workaround bc it's not wise to use
00129   // static members inside of template functions.  This should be revisited
00130   // after a more "correct" approach has been decided.
00131   _GetUnsignedAttributes(attrVector);
00132   
00133   //GetUnprotectedAttributes (IPKIFParseAttributes* m, attrVector);
00134  
00135   CPKIFStringPtr oidStr(new std::string(T::extOID));
00136   CPKIFOID oid(oidStr);
00137 
00138   CPKIFAttribute* p = NULL;
00139   std::vector<CPKIFAttributePtr>::iterator pos;
00140   std::vector<CPKIFAttributePtr>::iterator end = attrVector.end();
00141   for(pos = attrVector.begin(); pos != end; ++pos)
00142   {
00143     p = &(*(*pos));
00144     if(oid == (*pos)->GetOID() && NULL != dynamic_cast<T*>(p))
00145     {
00146       return *((boost::shared_ptr<T>*)&(*pos));
00147     }
00148   }     
00149 
00150   boost::shared_ptr<T> nullExt;
00151   return nullExt;
00152 }
00153 
00161 template <class T> boost::shared_ptr<T> CPKIFSignerInfo::GetSignedAttribute()
00162 {
00163   //XXX*** Read the comments below and fix this please 
00164   
00165   std::vector<CPKIFAttributePtr> attrVector;
00166   // The following function is a workaround bc it's not wise to use
00167   // static members inside of template functions.  This should be revisited
00168   // after a more "correct" approach has been decided.
00169   _GetSignedAttributes(attrVector);
00170   
00171   //GetUnprotectedAttributes (IPKIFParseAttributes* m, attrVector);
00172  
00173   CPKIFStringPtr oidStr(new std::string(T::extOID));
00174   CPKIFOID oid(oidStr);
00175 
00176   CPKIFAttribute* p = NULL;
00177   std::vector<CPKIFAttributePtr>::iterator pos;
00178   std::vector<CPKIFAttributePtr>::iterator end = attrVector.end();
00179   for(pos = attrVector.begin(); pos != end; ++pos)
00180   {
00181     p = &(*(*pos));
00182     if(oid == (*pos)->GetOID() && NULL != dynamic_cast<T*>(p))
00183     {
00184       return *((boost::shared_ptr<T>*)&(*pos));
00185     }
00186   }     
00187 
00188   boost::shared_ptr<T> nullExt;
00189   return nullExt;
00190 }
00191 
00192 #endif //__SIGNERINFO_H__

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