00001 00010 #include "SubtreeMatch.h" 00011 00012 #include "GeneralSubtree.h" 00013 #include "GeneralName.h" 00014 #include "Name.h" 00015 00016 #include "PKIFException.h" 00017 #include "PKIFCommonErrors.h" 00018 00019 00020 00030 // GIB: inverted the meaning of this operator. matches will now be considered disjoint 00031 bool SubtreeMatch::operator()(const CPKIFGeneralSubtreePtr& lhs) 00032 { 00033 // since callers may rely on this to throw COMMON_UNSUPPORTED_CHOICE if 00034 // one or both isn't supported (i.e. for determining whether name constraints 00035 // were processed) check that before checking equality 00036 CPKIFGeneralNamePtr rhsGN = m_rhs->GetBase(); 00037 CPKIFGeneralNamePtr lhsGN = lhs->GetBase(); 00038 CPKIFGeneralName::GENNAMETYPE lhsType = lhsGN->GetType(); 00039 CPKIFGeneralName::GENNAMETYPE rhsType = rhsGN->GetType(); 00040 if(!CPKIFGeneralSubtree::IsSupported(lhsType) || !CPKIFGeneralSubtree::IsSupported(rhsType)) 00041 { 00042 throw CPKIFException(TOOLKIT_PATH_MISC, COMMON_UNSUPPORTED_CHOICE, "Name constraint features an unsupported name component"); 00043 } 00044 // if they're identical, keep them 00045 if(*lhs == *m_rhs) 00046 { 00047 return false; 00048 // if they're unrelated, keep them 00049 } else if(lhsType != rhsType) 00050 { 00051 return false; 00052 } 00053 // if they're not dn's, see if they're rhs *fails* to satisfy lhs 00054 else if(lhsType != CPKIFGeneralName::DIRECTORYNAME) 00055 { 00056 if(CPKIFGeneralSubtree::NO_MATCH == lhs->IsInSubtree(rhsGN)) { 00057 // XXX TODO: do we need to do better than this for non directory name subtrees? 00058 return true; 00059 } 00060 } 00061 else 00062 { 00063 //eliminiated direct ->GetBase()->directoryName() call until after checking type (else crash) 12/2/2003 00064 CPKIFNamePtr subtreeName = m_rhs->GetBase()->directoryName(); 00065 CPKIFNamePtr subject = lhs->GetBase()->directoryName(); 00066 if (!subtreeName->DescendedFrom(*subject)) 00067 { 00068 return true; 00069 } 00070 } 00071 return false; 00072 } 00080 void SubtreeMatch::SetRHS( 00082 CPKIFGeneralSubtreePtr& rhs) {m_rhs = rhs;}