DistributionPointName.cpp
Go to the documentation of this file.00001
00009 #include "DistributionPointName.h"
00010 #include "GeneralName.h"
00011 #include "GeneralNamesCompare.h"
00012 #include "ASN1Helper.h"
00013 #include "PKIX1Implicit88.h"
00014 #include "PKIX1Explicit88.h"
00015 #include "Name.h"
00016 #include "ToolkitUtils.h"
00017
00018 #include <algorithm>
00019
00021
00022 struct CPKIFDistributionPointNameImpl
00023 {
00024 CPKIFGeneralNameList m_fullName;
00025 CACX509V3RDNSequence* m_relativeName;
00026 bool m_bNameRelativeToIssuerPresent;
00027 };
00028
00030
00038 CPKIFDistributionPointName::CPKIFDistributionPointName()
00039 :m_impl (new CPKIFDistributionPointNameImpl)
00040 {
00041 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 CPKIFDistributionPointName::CPKIFDistributionPointName(
00076 const CPKIFBufferPtr& name)
00077 :m_impl (new CPKIFDistributionPointNameImpl)
00078 {
00079
00080 CACASNWRAPPER_CREATE(CACX509V3DistributionPointName, objPDU);
00081 objPDU.Decode(name->GetBuffer(), name->GetLength());
00082
00083 if(2 == objPDU->t)
00084 {
00085 m_impl->m_bNameRelativeToIssuerPresent = true;
00086
00087 m_impl->m_relativeName = new CACX509V3RDNSequence;
00088 m_impl->m_relativeName->head = NULL; m_impl->m_relativeName->tail = NULL;
00089 m_impl->m_relativeName->count = 0;
00090
00091 DListNode* cur = NULL, *cur2 = objPDU->u.nameRelativeToCRLIssuer->head;
00092 ASN1OpenType* tmp = NULL, *tmp2 = NULL;
00093
00094
00095 for(unsigned int ii = 0; ii < objPDU->u.nameRelativeToCRLIssuer->count; ++ii)
00096 {
00097 if(NULL == cur)
00098 {
00099 NEW_NODE(cur)
00100 }
00101 else
00102 {
00103 NEW_NEXT_AND_ADVANCE(cur)
00104 }
00105
00106
00107
00108 tmp = new ASN1OpenType;
00109 CACX509V3AttributeTypeAndValue* tmpATV = (CACX509V3AttributeTypeAndValue*)cur2->data;
00110
00111
00112
00113 DList rdnList;
00114 DListNode rdnNode;
00115 rdnList.count = 1;
00116 rdnNode.data = tmpATV;
00117 rdnNode.next = NULL;
00118 rdnNode.prev = NULL;
00119 rdnList.head = &rdnNode;
00120 rdnList.tail = &rdnNode;
00121 CACASNWRAPPER_CREATE(CACX509V3RelativeDistinguishedName, rdnEncoder);
00122 tmp2 = rdnEncoder.Encode(&rdnList);
00123
00124
00125
00126 tmp->numocts = tmp2->numocts;
00127 tmp->data = new unsigned char[tmp->numocts];
00128 memcpy((void*)tmp->data, tmp2->data, tmp->numocts);
00129 delete tmp2;
00130
00131 cur->data = tmp;
00132 cur2 = cur2->next;
00133
00134
00135
00136
00137 if(0 == m_impl->m_relativeName->head)
00138 {
00139 m_impl->m_relativeName->head = cur;
00140 m_impl->m_relativeName->tail = cur;
00141 }
00142 else
00143 m_impl->m_relativeName->tail = cur;
00144 ++m_impl->m_relativeName->count;
00145 }
00146
00147 return;
00148 }
00149 else
00150 {
00151 m_impl->m_bNameRelativeToIssuerPresent = false;
00152
00153 DListNode* cur = objPDU->u.fullName->head;
00154 for(unsigned int ii = 0; ii < objPDU->u.fullName->count; ++ii)
00155 {
00156
00157
00158
00159 CACASNWRAPPER_CREATE(CACX509V3GeneralName, objPDU);
00160 ASN1OpenType* data1 = objPDU.Encode((CACX509V3GeneralName*)cur->data);
00161 CPKIFBufferPtr tmpBuf;
00162 if (data1 != NULL)
00163 {
00164 tmpBuf = CPKIFBufferPtr(new CPKIFBuffer(data1->data, data1->numocts));
00165 delete data1;
00166 }
00167 CPKIFGeneralNamePtr tmpGN(new CPKIFGeneralName(tmpBuf));
00168
00169 m_impl->m_fullName.push_back(tmpGN);
00170
00171 cur = cur->next;
00172 }
00173 }
00174 }
00175
00176
00177
00178
00179
00187 CPKIFDistributionPointName::~CPKIFDistributionPointName()
00188 {
00189 if(m_impl)
00190 {
00191 delete m_impl;
00192 m_impl = 0;
00193 }
00194 }
00205 bool CPKIFDistributionPointName::operator == (const CPKIFDistributionPointName& name)
00206 {
00207 CPKIFGeneralNameList rhs;
00208 name.FullName(rhs);
00209
00210 GeneralNamesCompare gnc;
00211 gnc.SetGeneralNames(&rhs);
00212
00213 CPKIFGeneralNameList::iterator end = m_impl->m_fullName.end();
00214 if(end != std::find_if(m_impl->m_fullName.begin(), m_impl->m_fullName.end(), gnc))
00215 return true;
00216 else
00217 return false;
00218 }
00226 bool CPKIFDistributionPointName::NameRelativeToIssuerPresent() const
00227 {
00228 return m_impl->m_bNameRelativeToIssuerPresent;
00229 }
00238 void CPKIFDistributionPointName::FullName(
00241 CPKIFGeneralNameList& genNames) const
00242 {
00243 genNames.clear();
00244
00245 CPKIFGeneralNameList::const_iterator pos;
00246 CPKIFGeneralNameList::const_iterator end = m_impl->m_fullName.end();
00247 for(pos = m_impl->m_fullName.begin(); pos != end; ++pos)
00248 {
00249 genNames.push_back(*pos);
00250 }
00251 }
00252
00254
00255 struct CPKIFNameImpl
00256 {
00257 CACX509V3Name* m_name;
00258 CPKIFStringPtr m_string;
00259 CPKIFBufferPtr m_encodedName;
00260 };
00261
00263
00271 CPKIFNamePtr CPKIFDistributionPointName::GetRelativeNameAsFullName(CPKIFNamePtr& issuerName)
00272 {
00273 CPKIFNamePtr newName(new CPKIFName(issuerName->Encoded()));
00274
00275 DListNode* cur = newName->m_impl->m_name->u.rdnSequence->tail, *cur2 = m_impl->m_relativeName->head;
00276 ASN1OpenType* tmp = NULL, *tmp2 = NULL;
00277
00278 for(unsigned int ii = 0; ii < m_impl->m_relativeName->count; ++ii)
00279 {
00280 if(NULL == cur)
00281 {
00282 NEW_NODE(cur)
00283 }
00284 else
00285 {
00286 NEW_NEXT_AND_ADVANCE(cur)
00287 }
00288
00289
00290
00291 tmp = new ASN1OpenType;
00292 tmp2 = (ASN1OpenType*)cur2->data;
00293
00294
00295
00296 tmp->numocts = tmp2->numocts;
00297 tmp->data = new unsigned char[tmp->numocts];
00298 memcpy((void*)tmp->data, tmp2->data, tmp->numocts);
00299
00300 cur->data = tmp;
00301 cur2 = cur2->next;
00302
00303
00304
00305
00306 if(0 == newName->m_impl->m_name->u.rdnSequence->head)
00307 {
00308 newName->m_impl->m_name->u.rdnSequence->head = cur;
00309 newName->m_impl->m_name->u.rdnSequence->tail = cur;
00310 }
00311 else
00312 newName->m_impl->m_name->u.rdnSequence->tail = cur;
00313 ++newName->m_impl->m_name->u.rdnSequence->count;
00314 }
00315
00316 return newName;
00317 }