Attribute.cpp

Go to the documentation of this file.
00001 
00009 #include "Attribute.h"
00010 #include "Buffer.h"
00011 #include "OID.h"
00012 
00013 #include "ToolkitUtils.h"
00014 #include "ASN1Helper.h"
00015 #include "PKIFMessageException.h"
00016 
00017 #include "CryptographicMessageSyntax2004.h"
00018 
00019 #include <iterator>
00021 struct CPKIFAttributeImpl
00022 {
00023   CPKIFAttribute *m_parent;
00024 
00025   CPKIFOIDPtr m_oid;
00026   CPKIFBufferList m_content;
00027 
00028   void ParseAttributes (const unsigned char *buf, const unsigned int length);
00029 };
00037 void CPKIFAttributeImpl::ParseAttributes (
00039     const unsigned char *buf, 
00041     const unsigned int length)
00042 {
00043     CACASNWRAPPER_CREATE(CACCMSAttributeValues, attrsVals);
00044     CACCMSAttributeValues* attributesList = attrsVals.Decode(buf, length);
00045 
00046     DListNode* node = NULL;
00047     if(attributesList->count > 0)
00048         node = attributesList->head;
00049 
00050     while(NULL != node)
00051     {
00052         ASN1OpenType* ot = (ASN1OpenType*)node->data;
00053 
00054         try
00055         {
00056             CPKIFBufferPtr tmpBuf(new CPKIFBuffer(ot->data, ot->numocts));
00057             m_parent->AddValue(tmpBuf);
00058         }
00059         catch(std::bad_alloc& ba)
00060         {
00061             m_content.clear();
00062             throw ba;
00063         }
00064 
00065         node = node->next;
00066     }
00067 }
00068 
00070 
00078 CPKIFAttribute::CPKIFAttribute()
00079     :m_impl (new CPKIFAttributeImpl)
00080 {
00081   m_impl->m_parent = this;
00082   LOG_STRING_DEBUG("CPKIFAttribute::CPKIFAttribute()", TOOLKIT_MESSAGE_ASN, 0, this);
00083 }
00094 /*CPKIFAttribute::CPKIFAttribute(
00096     CACCMSAttribute& attr)
00097     :m_impl (new CPKIFAttributeImpl)
00098 {
00099   m_impl->m_parent = this;
00100 
00101   LOG_STRING_DEBUG("CPKIFAttribute::CPKIFAttribute(CACCMSAttribute& attr)", TOOLKIT_MESSAGE_ASN, 0, this);
00102 
00103   //throw bad_alloc
00104   CPKIFOIDPtr tmpOID(new CPKIFOID(attr.attrType));
00105   SetOID(tmpOID);
00106 
00107   m_impl->ParseAttributes (attr.attrValues.data, attr.attrValues.numocts);
00108 }
00109 
00110 */
00118 CPKIFAttribute::CPKIFAttribute(
00120     const CPKIFOIDPtr& oid,
00122     const CPKIFBufferPtr& attr)
00123   : m_impl (new CPKIFAttributeImpl)
00124 {
00125   m_impl->m_parent = this;
00126 
00127   SetOID (oid);
00128   m_impl->ParseAttributes (attr->GetBuffer(), attr->GetLength());
00129 }
00137 CPKIFAttribute::CPKIFAttribute(
00139     const CPKIFBufferPtr& attr)
00140 : m_impl (new CPKIFAttributeImpl)
00141 {
00142   m_impl->m_parent = this;
00143   m_impl->ParseAttributes (attr->GetBuffer(), attr->GetLength());
00144 }
00145 
00153 CPKIFAttribute::~CPKIFAttribute()
00154 {
00155     LOG_STRING_DEBUG("CPKIFAttribute::~CPKIFAttribute()", TOOLKIT_MESSAGE_ASN, 0, this);
00156 
00157     if (m_impl)
00158     {   
00159       delete m_impl;
00160       m_impl = 0;
00161     }
00162 }
00163 
00177 void CPKIFAttribute::SetOID(
00180     const CPKIFOIDPtr& oid) 
00181 {
00182     LOG_STRING_DEBUG("CPKIFAttribute::SetOID(CPKIFOIDPtr& oid)", TOOLKIT_MESSAGE_ASN, 0, this);
00183 
00184     //accept no NULLs
00185     if(oid == (CPKIFOID*)NULL)
00186         throw CPKIFMessageException(TOOLKIT_MESSAGE, COMMON_INVALID_INPUT);
00187 
00188     m_impl->m_oid = oid;
00189 }
00198 CPKIFOIDPtr CPKIFAttribute::GetOID() const 
00199 {
00200     return m_impl->m_oid;
00201 }
00218 void CPKIFAttribute::AddValue(
00220     CPKIFBufferPtr& buf) 
00221 {
00222     LOG_STRING_DEBUG("CPKIFAttribute::AddValue(CPKIFBufferPtr& buf)", TOOLKIT_MESSAGE_ASN, 0, this);
00223 
00224     //accept no NULLs
00225     if(buf == (CPKIFBuffer*)NULL)
00226         throw CPKIFMessageException(TOOLKIT_MESSAGE, COMMON_INVALID_INPUT);
00227 
00228     m_impl->m_content.push_back(buf);
00229 }
00240 void CPKIFAttribute::GetValues(
00242     CPKIFBufferList& values) const 
00243 {
00244     LOG_STRING_DEBUG("CPKIFAttribute::GetValues(CPKIFBufferList& values)", TOOLKIT_MESSAGE_ASN, 0, this);
00245 
00246     values.clear();
00247     copy(m_impl->m_content.begin(), m_impl->m_content.end(), back_inserter(values));
00248 }

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