ContentWithAttributes.cpp

Go to the documentation of this file.
00001 
00009 #include "ContentWithAttributes.h"
00010 
00011 #include "ContentInfo.h"
00012 #include "Buffer.h"
00013 #include "Attribute.h"
00014 
00015 #include "PKIFCredential.h"
00016 #include "PKIFKeyMaterial.h"
00017 
00018 #include "PKIFCMSAttributeMediator2.h"
00019 #include "ToolkitUtils.h"
00020 #include "PKIFMessageException.h"
00021 #include "PKIFMessageErrors.h"
00022 #include "ASN1Helper.h"
00023 #include "PKIFCMSUtils.h"
00024 
00025 #include "ContentCollectionModule.h"
00026 #include "CryptographicMessageSyntax2004.h"
00027 
00028 #include <iterator>
00030 struct CPKIFContentWithAttributesImpl
00031 {
00032     //structure members
00033     CPKIFContentInfoPtr m_contentInfo;
00034     CPKIFAttributeList m_attributes;
00035     //signature alg determined from credential, signature value calculated
00036 
00037     void populateAttributesVector(const CACCMSUnsignedAttributes& ua);
00038     bool m_bDecoded;
00039 
00040     CPKIFBufferPtr unencodedAttrBuffer;
00041 };
00043 
00051 CPKIFContentWithAttributes::CPKIFContentWithAttributes()
00052     :m_impl (new CPKIFContentWithAttributesImpl)
00053 {
00054     m_impl->m_bDecoded = false;
00055     SetContentType(g_contentWithAttributes);
00056 }
00057 
00067 void CPKIFContentWithAttributes::Decode(
00069     //const CACCMSSignerInfo& si
00070     CPKIFBufferPtr& siBuf)
00071 {
00072     CACASNWRAPPER_CREATE(ContentWithAttributes, InfoWrapper);
00073     InfoWrapper.Decode(siBuf->GetBuffer(), siBuf->GetLength()); 
00074 
00075     CPKIFOIDPtr tmpOID(new CPKIFOID(InfoWrapper->content.contentType.subid, InfoWrapper->content.contentType.numids));
00076     CPKIFBufferPtr tmpBuff(new CPKIFBuffer(InfoWrapper->content.content.data, InfoWrapper->content.content.numocts));
00077     CPKIFContentInfoPtr ci(new CPKIFContentInfo(tmpOID, tmpBuff));
00078 
00079     m_impl->m_contentInfo = ci;
00080 
00081 
00082     
00083     CACASNWRAPPER_CREATE(ContentWithAttributes_attrs, attrWrapper);
00084     ASN1OpenType *data = attrWrapper.Encode (&InfoWrapper->attrs);
00085     CPKIFBufferPtr tmp(new CPKIFBuffer(data->data, data->numocts));
00086     m_impl->unencodedAttrBuffer = tmp;
00087     delete data;
00088 
00089     m_impl->m_bDecoded = true;
00090 }
00091 
00099 void CPKIFContentWithAttributes::GetEncodedAttributes (
00101     CPKIFBufferPtr& buf) {
00102   if (m_impl)
00103   {
00104       buf = m_impl->unencodedAttrBuffer;
00105   }
00106   else
00107   {
00108     CPKIFBufferPtr nullExt;
00109     buf = nullExt;
00110   }
00111 }
00112 
00113 
00121 CPKIFContentWithAttributes::~CPKIFContentWithAttributes()
00122 {
00123     delete m_impl;
00124     m_impl = NULL;
00125 }
00136 bool CPKIFContentWithAttributes::Decoded() const
00137 {
00138     return m_impl->m_bDecoded;
00139 }
00140 
00148 void CPKIFContentWithAttributes::GetAttributes(
00150     CPKIFAttributeList& ual)
00151 {
00152     CPKIFCMSAttributeMediator2* mediator = CPKIFCMSAttributeMediator2::GetInstance();
00153 
00154     std::vector<CPKIFAttributePtr> tmpList;
00155     this->IPKIFHasAttributes::GetAttributes(mediator, tmpList);
00156 
00157     copy(tmpList.begin(),tmpList.end(), back_inserter(ual));
00158 }
00168 void CPKIFContentWithAttributes::AddAttribute(
00170     CPKIFAttributePtr& ua)
00171 {
00172     //accept no NULLs
00173     if(ua == (CPKIFAttribute*)NULL)
00174         throw CPKIFMessageException(TOOLKIT_MESSAGE, COMMON_INVALID_INPUT);
00175 
00176     m_impl->m_attributes.push_back(ua);
00177 }
00185 void CPKIFContentWithAttributesImpl::populateAttributesVector(
00187     const ContentWithAttributes_attrs& ua)
00188 {
00189     //if we've already populated the extensions vector then return
00190     if(!m_attributes.empty())
00191         return;
00192 
00193     //if there are no extensions then return
00194     if(0 == ua.count)
00195     {
00196         m_attributes.clear();
00197         return;
00198     }
00199 
00200     //create an extensions mediator using the default extension colleagues and initialize it
00201     CPKIFCMSAttributeMediator2* mediator = CPKIFCMSAttributeMediator2::GetInstance();
00202 
00203     //iterate over the list of extensions and populate the extensions vector
00204     DListNode* cur = ua.head;
00205     for(unsigned int ii = 0; ii < ua.count; ++ii)
00206     {
00207         CACCMSAttribute* attr = (CACCMSAttribute*) cur->data;
00208         CPKIFOIDPtr oid(new CPKIFOID(attr->attrType.subid, attr->attrType.numids));
00209         CPKIFBufferPtr buf(new CPKIFBuffer(attr->attrValues.data, attr->attrValues.numocts));
00210 
00211         m_attributes.push_back(mediator->getAttribute(oid, buf));
00212         cur = cur->next;
00213     }
00214 }
00222 void CPKIFContentWithAttributes::_GetAttributes(
00224     std::vector<CPKIFAttributePtr>& attrVector)
00225 {
00226     CPKIFCMSAttributeMediator2* mediator = CPKIFCMSAttributeMediator2::GetInstance();
00227     this->IPKIFHasAttributes::GetAttributes(mediator, attrVector);
00228 }
00236 void CPKIFContentWithAttributes::GetAddedAttributes(
00238     std::vector<CPKIFAttributePtr>& attr)
00239 {
00240   CPKIFAttributeList::iterator pos;
00241   CPKIFAttributeList::iterator end = m_impl->m_attributes.end();
00242   for (pos = m_impl->m_attributes.begin(); pos != end; pos++)
00243   {
00244     attr.push_back (*pos);
00245   }
00246 }
00254 void CPKIFContentWithAttributes::SetContentInfo(
00256     CPKIFContentInfoPtr& contentInfo)
00257 {
00258     m_impl->m_contentInfo = contentInfo;
00259 }
00267 CPKIFContentInfoPtr CPKIFContentWithAttributes::GetContentInfo() const
00268 {
00269     return m_impl->m_contentInfo;
00270 }
00278 CPKIFBufferPtr CPKIFContentWithAttributes::Encode()
00279 {
00280     RAISE_MESSAGE_EXCEPTION("Content collection creation is not supported in this version.", thisComponent, COMMON_NOT_IMPLEMENTED, this);
00281 }

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