andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * pkix_policynode.c andre@0: * andre@0: * Policy Node Object Type Definition andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_policynode.h" andre@0: andre@0: /* --Private-PolicyNode-Functions---------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_GetChildrenMutable andre@0: * DESCRIPTION: andre@0: * andre@0: * Retrieves the List of PolicyNodes representing the child nodes of the andre@0: * Policy Node pointed to by "node" and stores it at "pChildren". If "node" andre@0: * has no List of child nodes, this function stores NULL at "pChildren". andre@0: * andre@0: * Note that the List returned by this function may be mutable. This function andre@0: * differs from the public function PKIX_PolicyNode_GetChildren in that andre@0: * respect. (It also differs in that the public function creates an empty andre@0: * List, if necessary, rather than storing NULL.) andre@0: * andre@0: * During certificate processing, children Lists are created and modified. andre@0: * Once the list is accessed using the public call, the List is set immutable. andre@0: * andre@0: * PARAMETERS: andre@0: * "node" andre@0: * Address of PolicyNode whose child nodes are to be stored. andre@0: * Must be non-NULL. andre@0: * "pChildren" andre@0: * Address where object pointer will be stored. Must be non-NULL. andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_PolicyNode_GetChildrenMutable( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_List **pChildren, /* list of PKIX_PolicyNode */ andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_GetChildrenMutable"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pChildren); andre@0: andre@0: PKIX_INCREF(node->children); andre@0: andre@0: *pChildren = node->children; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Create andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a new PolicyNode using the OID pointed to by "validPolicy", the List andre@0: * of CertPolicyQualifiers pointed to by "qualifierSet", the criticality andre@0: * indicated by the Boolean value of "criticality", and the List of OIDs andre@0: * pointed to by "expectedPolicySet", and stores the result at "pObject". The andre@0: * criticality should be derived from whether the certificate policy extension andre@0: * was marked as critical in the certificate that led to creation of this andre@0: * PolicyNode. The "qualifierSet" and "expectedPolicySet" Lists are made andre@0: * immutable. The PolicyNode pointers to parent and to children are initialized andre@0: * to NULL, and the depth is set to zero; those values should be set by using andre@0: * the pkix_PolicyNode_AddToParent function. andre@0: * andre@0: * PARAMETERS andre@0: * "validPolicy" andre@0: * Address of OID of the valid policy for the path. Must be non-NULL andre@0: * "qualifierSet" andre@0: * Address of List of CertPolicyQualifiers associated with the validpolicy. andre@0: * May be NULL andre@0: * "criticality" andre@0: * Boolean indicator of whether the criticality should be set in this andre@0: * PolicyNode andre@0: * "expectedPolicySet" andre@0: * Address of List of OIDs that would satisfy this policy in the next andre@0: * certificate. Must be non-NULL andre@0: * "pObject" andre@0: * Address where the PolicyNode pointer will be stored. Must be non-NULL. andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_PolicyNode_Create( andre@0: PKIX_PL_OID *validPolicy, andre@0: PKIX_List *qualifierSet, andre@0: PKIX_Boolean criticality, andre@0: PKIX_List *expectedPolicySet, andre@0: PKIX_PolicyNode **pObject, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *node = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Create"); andre@0: andre@0: PKIX_NULLCHECK_THREE(validPolicy, expectedPolicySet, pObject); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_CERTPOLICYNODE_TYPE, andre@0: sizeof (PKIX_PolicyNode), andre@0: (PKIX_PL_Object **)&node, andre@0: plContext), andre@0: PKIX_COULDNOTCREATEPOLICYNODEOBJECT); andre@0: andre@0: PKIX_INCREF(validPolicy); andre@0: node->validPolicy = validPolicy; andre@0: andre@0: PKIX_INCREF(qualifierSet); andre@0: node->qualifierSet = qualifierSet; andre@0: if (qualifierSet) { andre@0: PKIX_CHECK(PKIX_List_SetImmutable(qualifierSet, plContext), andre@0: PKIX_LISTSETIMMUTABLEFAILED); andre@0: } andre@0: andre@0: node->criticality = criticality; andre@0: andre@0: PKIX_INCREF(expectedPolicySet); andre@0: node->expectedPolicySet = expectedPolicySet; andre@0: PKIX_CHECK(PKIX_List_SetImmutable(expectedPolicySet, plContext), andre@0: PKIX_LISTSETIMMUTABLEFAILED); andre@0: andre@0: node->parent = NULL; andre@0: node->children = NULL; andre@0: node->depth = 0; andre@0: andre@0: *pObject = node; andre@0: node = NULL; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(node); andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_AddToParent andre@0: * DESCRIPTION: andre@0: * andre@0: * Adds the PolicyNode pointed to by "child" to the List of children of andre@0: * the PolicyNode pointed to by "parentNode". If "parentNode" had a andre@0: * NULL pointer for the List of children, a new List is created containing andre@0: * "child". Otherwise "child" is appended to the existing List. The andre@0: * parent field in "child" is set to "parent", and the depth field is andre@0: * set to one more than the corresponding value in "parent". andre@0: * andre@0: * Depth, in this context, means distance from the root node, which andre@0: * is at depth zero. andre@0: * andre@0: * PARAMETERS: andre@0: * "parentNode" andre@0: * Address of PolicyNode whose List of child PolicyNodes is to be andre@0: * created or appended to. Must be non-NULL. andre@0: * "child" andre@0: * Address of PolicyNode to be added to parentNode's List. Must be andre@0: * non-NULL. andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Not Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_PolicyNode_AddToParent( andre@0: PKIX_PolicyNode *parentNode, andre@0: PKIX_PolicyNode *child, andre@0: void *plContext) andre@0: { andre@0: PKIX_List *listOfChildren = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_AddToParent"); andre@0: andre@0: PKIX_NULLCHECK_TWO(parentNode, child); andre@0: andre@0: listOfChildren = parentNode->children; andre@0: if (listOfChildren == NULL) { andre@0: PKIX_CHECK(PKIX_List_Create(&listOfChildren, plContext), andre@0: PKIX_LISTCREATEFAILED); andre@0: parentNode->children = listOfChildren; andre@0: } andre@0: andre@0: /* andre@0: * Note: this link is not reference-counted. The link from parent andre@0: * to child is counted (actually, the parent "owns" a List which andre@0: * "owns" children), but the children do not "own" the parent. andre@0: * Otherwise, there would be loops. andre@0: */ andre@0: child->parent = parentNode; andre@0: andre@0: child->depth = 1 + (parentNode->depth); andre@0: andre@0: PKIX_CHECK(PKIX_List_AppendItem andre@0: (listOfChildren, (PKIX_PL_Object *)child, plContext), andre@0: PKIX_COULDNOTAPPENDCHILDTOPARENTSPOLICYNODELIST); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_InvalidateCache andre@0: ((PKIX_PL_Object *)parentNode, plContext), andre@0: PKIX_OBJECTINVALIDATECACHEFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_InvalidateCache andre@0: ((PKIX_PL_Object *)child, plContext), andre@0: PKIX_OBJECTINVALIDATECACHEFAILED); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Prune andre@0: * DESCRIPTION: andre@0: * andre@0: * Prunes a tree below the PolicyNode whose address is pointed to by "node", andre@0: * using the UInt32 value of "height" as the distance from the leaf level, andre@0: * and storing at "pDelete" the Boolean value of whether this PolicyNode is, andre@0: * after pruning, childless and should be pruned. andre@0: * andre@0: * Any PolicyNode at height 0 is allowed to survive. If the height is greater andre@0: * than zero, pkix_PolicyNode_Prune is called recursively for each child of andre@0: * the current PolicyNode. After this process, a node with no children andre@0: * stores PKIX_TRUE in "pDelete" to indicate that it should be deleted. andre@0: * andre@0: * PARAMETERS: andre@0: * "node" andre@0: * Address of the PolicyNode to be pruned. Must be non-NULL. andre@0: * "height" andre@0: * UInt32 value for the distance from the leaf level andre@0: * "pDelete" andre@0: * Address to store the Boolean return value of PKIX_TRUE if this node andre@0: * should be pruned, or PKIX_FALSE if there remains at least one andre@0: * branch of the required height. Must be non-NULL. andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Not Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_PolicyNode_Prune( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_UInt32 height, andre@0: PKIX_Boolean *pDelete, andre@0: void *plContext) andre@0: { andre@0: PKIX_Boolean childless = PKIX_FALSE; andre@0: PKIX_Boolean shouldBePruned = PKIX_FALSE; andre@0: PKIX_UInt32 listSize = 0; andre@0: PKIX_UInt32 listIndex = 0; andre@0: PKIX_PolicyNode *candidate = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Prune"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pDelete); andre@0: andre@0: /* Don't prune at the leaf */ andre@0: if (height == 0) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* Above the bottom level, childless nodes get pruned */ andre@0: if (!(node->children)) { andre@0: childless = PKIX_TRUE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* andre@0: * This node has children. If they are leaf nodes, andre@0: * we know they will live. Otherwise, check them out. andre@0: */ andre@0: if (height > 1) { andre@0: PKIX_CHECK(PKIX_List_GetLength andre@0: (node->children, &listSize, plContext), andre@0: PKIX_LISTGETLENGTHFAILED); andre@0: /* andre@0: * By working backwards from the end of the list, andre@0: * we avoid having to worry about possible andre@0: * decreases in the size of the list, as we andre@0: * delete items. The only nuisance is that since the andre@0: * index is UInt32, we can't check for it to reach -1; andre@0: * we have to use the 1-based index, rather than the andre@0: * 0-based index that PKIX_List functions require. andre@0: */ andre@0: for (listIndex = listSize; listIndex > 0; listIndex--) { andre@0: PKIX_CHECK(PKIX_List_GetItem andre@0: (node->children, andre@0: (listIndex - 1), andre@0: (PKIX_PL_Object **)&candidate, andre@0: plContext), andre@0: PKIX_LISTGETITEMFAILED); andre@0: andre@0: PKIX_CHECK(pkix_PolicyNode_Prune andre@0: (candidate, andre@0: height - 1, andre@0: &shouldBePruned, andre@0: plContext), andre@0: PKIX_POLICYNODEPRUNEFAILED); andre@0: andre@0: if (shouldBePruned == PKIX_TRUE) { andre@0: PKIX_CHECK(PKIX_List_DeleteItem andre@0: (node->children, andre@0: (listIndex - 1), andre@0: plContext), andre@0: PKIX_LISTDELETEITEMFAILED); andre@0: } andre@0: andre@0: PKIX_DECREF(candidate); andre@0: } andre@0: } andre@0: andre@0: /* Prune if this node has *become* childless */ andre@0: PKIX_CHECK(PKIX_List_GetLength andre@0: (node->children, &listSize, plContext), andre@0: PKIX_LISTGETLENGTHFAILED); andre@0: if (listSize == 0) { andre@0: childless = PKIX_TRUE; andre@0: } andre@0: andre@0: /* andre@0: * Even if we did not change this node, or any of its children, andre@0: * maybe a [great-]*grandchild was pruned. andre@0: */ andre@0: PKIX_CHECK(PKIX_PL_Object_InvalidateCache andre@0: ((PKIX_PL_Object *)node, plContext), andre@0: PKIX_OBJECTINVALIDATECACHEFAILED); andre@0: andre@0: cleanup: andre@0: *pDelete = childless; andre@0: andre@0: PKIX_DECREF(candidate); andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_SinglePolicyNode_ToString andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a String representation of the attributes of the PolicyNode andre@0: * pointed to by "node", other than its parents or children, and andre@0: * stores the result at "pString". andre@0: * andre@0: * PARAMETERS: andre@0: * "node" andre@0: * Address of PolicyNode to be described by the string. Must be non-NULL. andre@0: * "pString" andre@0: * Address where object pointer will be stored. Must be non-NULL. andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if function succeeds andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in a fatal way andre@0: */ andre@0: PKIX_Error * andre@0: pkix_SinglePolicyNode_ToString( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_String *fmtString = NULL; andre@0: PKIX_PL_String *validString = NULL; andre@0: PKIX_PL_String *qualifierString = NULL; andre@0: PKIX_PL_String *criticalityString = NULL; andre@0: PKIX_PL_String *expectedString = NULL; andre@0: PKIX_PL_String *outString = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_SinglePolicyNode_ToString"); andre@0: PKIX_NULLCHECK_TWO(node, pString); andre@0: PKIX_NULLCHECK_TWO(node->validPolicy, node->expectedPolicySet); andre@0: andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "{%s,%s,%s,%s,%d}", andre@0: 0, andre@0: &fmtString, andre@0: plContext), andre@0: PKIX_CANTCREATESTRING); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)(node->validPolicy), andre@0: &validString, andre@0: plContext), andre@0: PKIX_OIDTOSTRINGFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)(node->expectedPolicySet), andre@0: &expectedString, andre@0: plContext), andre@0: PKIX_LISTTOSTRINGFAILED); andre@0: andre@0: if (node->qualifierSet) { andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)(node->qualifierSet), andre@0: &qualifierString, andre@0: plContext), andre@0: PKIX_LISTTOSTRINGFAILED); andre@0: } else { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "{}", andre@0: 0, andre@0: &qualifierString, andre@0: plContext), andre@0: PKIX_CANTCREATESTRING); andre@0: } andre@0: andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: (node->criticality)?"Critical":"Not Critical", andre@0: 0, andre@0: &criticalityString, andre@0: plContext), andre@0: PKIX_CANTCREATESTRING); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&outString, andre@0: plContext, andre@0: fmtString, andre@0: validString, andre@0: qualifierString, andre@0: criticalityString, andre@0: expectedString, andre@0: node->depth), andre@0: PKIX_SPRINTFFAILED); andre@0: andre@0: *pString = outString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(fmtString); andre@0: PKIX_DECREF(validString); andre@0: PKIX_DECREF(qualifierString); andre@0: PKIX_DECREF(criticalityString); andre@0: PKIX_DECREF(expectedString); andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_ToString_Helper andre@0: * DESCRIPTION: andre@0: * andre@0: * Produces a String representation of a PolicyNode tree below the PolicyNode andre@0: * pointed to by "rootNode", with each line of output prefixed by the String andre@0: * pointed to by "indent", and stores the result at "pTreeString". It is andre@0: * called recursively, with ever-increasing indentation, for successively andre@0: * lower nodes on the tree. andre@0: * andre@0: * PARAMETERS: andre@0: * "rootNode" andre@0: * Address of PolicyNode subtree. Must be non-NULL. andre@0: * "indent" andre@0: * Address of String to be prefixed to each line of output. May be NULL andre@0: * if no indentation is desired andre@0: * "pTreeString" andre@0: * Address where the resulting String will be stored; must be non-NULL andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_ToString_Helper( andre@0: PKIX_PolicyNode *rootNode, andre@0: PKIX_PL_String *indent, andre@0: PKIX_PL_String **pTreeString, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_String *nextIndentFormat = NULL; andre@0: PKIX_PL_String *thisNodeFormat = NULL; andre@0: PKIX_PL_String *childrenFormat = NULL; andre@0: PKIX_PL_String *nextIndentString = NULL; andre@0: PKIX_PL_String *resultString = NULL; andre@0: PKIX_PL_String *thisItemString = NULL; andre@0: PKIX_PL_String *childString = NULL; andre@0: PKIX_PolicyNode *childNode = NULL; andre@0: PKIX_UInt32 numberOfChildren = 0; andre@0: PKIX_UInt32 childIndex = 0; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_ToString_Helper"); andre@0: andre@0: PKIX_NULLCHECK_TWO(rootNode, pTreeString); andre@0: andre@0: /* Create a string for this node */ andre@0: PKIX_CHECK(pkix_SinglePolicyNode_ToString andre@0: (rootNode, &thisItemString, plContext), andre@0: PKIX_ERRORINSINGLEPOLICYNODETOSTRING); andre@0: andre@0: if (indent) { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "%s%s", andre@0: 0, andre@0: &thisNodeFormat, andre@0: plContext), andre@0: PKIX_ERRORCREATINGFORMATSTRING); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&resultString, andre@0: plContext, andre@0: thisNodeFormat, andre@0: indent, andre@0: thisItemString), andre@0: PKIX_ERRORINSPRINTF); andre@0: } else { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "%s", andre@0: 0, andre@0: &thisNodeFormat, andre@0: plContext), andre@0: PKIX_ERRORCREATINGFORMATSTRING); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&resultString, andre@0: plContext, andre@0: thisNodeFormat, andre@0: thisItemString), andre@0: PKIX_ERRORINSPRINTF); andre@0: } andre@0: andre@0: PKIX_DECREF(thisItemString); andre@0: thisItemString = resultString; andre@0: andre@0: /* if no children, we are done */ andre@0: if (rootNode->children) { andre@0: PKIX_CHECK(PKIX_List_GetLength andre@0: (rootNode->children, &numberOfChildren, plContext), andre@0: PKIX_LISTGETLENGTHFAILED); andre@0: } andre@0: andre@0: if (numberOfChildren != 0) { andre@0: /* andre@0: * We create a string for each child in turn, andre@0: * concatenating them to thisItemString. andre@0: */ andre@0: andre@0: /* Prepare an indent string for each child */ andre@0: if (indent) { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "%s. ", andre@0: 0, andre@0: &nextIndentFormat, andre@0: plContext), andre@0: PKIX_ERRORCREATINGFORMATSTRING); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&nextIndentString, andre@0: plContext, andre@0: nextIndentFormat, andre@0: indent), andre@0: PKIX_ERRORINSPRINTF); andre@0: } else { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: ". ", andre@0: 0, andre@0: &nextIndentString, andre@0: plContext), andre@0: PKIX_ERRORCREATINGINDENTSTRING); andre@0: } andre@0: andre@0: /* Prepare the format for concatenation. */ andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: "%s\n%s", andre@0: 0, andre@0: &childrenFormat, andre@0: plContext), andre@0: PKIX_ERRORCREATINGFORMATSTRING); andre@0: andre@0: for (childIndex = 0; andre@0: childIndex < numberOfChildren; andre@0: childIndex++) { andre@0: PKIX_CHECK(PKIX_List_GetItem andre@0: (rootNode->children, andre@0: childIndex, andre@0: (PKIX_PL_Object **)&childNode, andre@0: plContext), andre@0: PKIX_LISTGETITEMFAILED); andre@0: andre@0: PKIX_CHECK(pkix_PolicyNode_ToString_Helper andre@0: (childNode, andre@0: nextIndentString, andre@0: &childString, andre@0: plContext), andre@0: PKIX_ERRORCREATINGCHILDSTRING); andre@0: andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&resultString, andre@0: plContext, andre@0: childrenFormat, andre@0: thisItemString, andre@0: childString), andre@0: PKIX_ERRORINSPRINTF); andre@0: andre@0: PKIX_DECREF(childNode); andre@0: PKIX_DECREF(childString); andre@0: PKIX_DECREF(thisItemString); andre@0: andre@0: thisItemString = resultString; andre@0: } andre@0: } andre@0: andre@0: *pTreeString = thisItemString; andre@0: andre@0: cleanup: andre@0: if (PKIX_ERROR_RECEIVED) { andre@0: PKIX_DECREF(thisItemString); andre@0: } andre@0: andre@0: PKIX_DECREF(nextIndentFormat); andre@0: PKIX_DECREF(thisNodeFormat); andre@0: PKIX_DECREF(childrenFormat); andre@0: PKIX_DECREF(nextIndentString); andre@0: PKIX_DECREF(childString); andre@0: PKIX_DECREF(childNode); andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pTreeString, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *rootNode = NULL; andre@0: PKIX_PL_String *resultString = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_ToString"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pTreeString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYNODE_TYPE, plContext), andre@0: PKIX_OBJECTNOTPOLICYNODE); andre@0: andre@0: rootNode = (PKIX_PolicyNode *)object; andre@0: andre@0: PKIX_CHECK(pkix_PolicyNode_ToString_Helper andre@0: (rootNode, NULL, &resultString, plContext), andre@0: PKIX_ERRORCREATINGSUBTREESTRING); andre@0: andre@0: *pTreeString = resultString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *node = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Destroy"); andre@0: andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYNODE_TYPE, plContext), andre@0: PKIX_OBJECTNOTPOLICYNODE); andre@0: andre@0: node = (PKIX_PolicyNode*)object; andre@0: andre@0: node->criticality = PKIX_FALSE; andre@0: PKIX_DECREF(node->validPolicy); andre@0: PKIX_DECREF(node->qualifierSet); andre@0: PKIX_DECREF(node->expectedPolicySet); andre@0: PKIX_DECREF(node->children); andre@0: andre@0: /* andre@0: * Note: the link to parent is not reference-counted. See comment andre@0: * in pkix_PolicyNode_AddToParent for more details. andre@0: */ andre@0: node->parent = NULL; andre@0: node->depth = 0; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_SinglePolicyNode_Hashcode andre@0: * DESCRIPTION: andre@0: * andre@0: * Computes the hashcode of the attributes of the PolicyNode pointed to by andre@0: * "node", other than its parents and children, and stores the result at andre@0: * "pHashcode". andre@0: * andre@0: * PARAMETERS: andre@0: * "node" andre@0: * Address of PolicyNode to be hashcoded; must be non-NULL andre@0: * "pHashcode" andre@0: * Address where UInt32 result will be stored; must be non-NULL andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if function succeeds andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in a fatal way andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_SinglePolicyNode_Hashcode( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_UInt32 componentHash = 0; andre@0: PKIX_UInt32 nodeHash = 0; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_SinglePolicyNode_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(node, pHashcode); andre@0: PKIX_NULLCHECK_TWO(node->validPolicy, node->expectedPolicySet); andre@0: andre@0: PKIX_HASHCODE andre@0: (node->qualifierSet, andre@0: &nodeHash, andre@0: plContext, andre@0: PKIX_FAILUREHASHINGLISTQUALIFIERSET); andre@0: andre@0: if (PKIX_TRUE == (node->criticality)) { andre@0: nodeHash = 31*nodeHash + 0xff; andre@0: } else { andre@0: nodeHash = 31*nodeHash + 0x00; andre@0: } andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)node->validPolicy, andre@0: &componentHash, andre@0: plContext), andre@0: PKIX_FAILUREHASHINGOIDVALIDPOLICY); andre@0: andre@0: nodeHash = 31*nodeHash + componentHash; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)node->expectedPolicySet, andre@0: &componentHash, andre@0: plContext), andre@0: PKIX_FAILUREHASHINGLISTEXPECTEDPOLICYSET); andre@0: andre@0: nodeHash = 31*nodeHash + componentHash; andre@0: andre@0: *pHashcode = nodeHash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *node = NULL; andre@0: PKIX_UInt32 childrenHash = 0; andre@0: PKIX_UInt32 nodeHash = 0; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType andre@0: (object, PKIX_CERTPOLICYNODE_TYPE, plContext), andre@0: PKIX_OBJECTNOTPOLICYNODE); andre@0: andre@0: node = (PKIX_PolicyNode *)object; andre@0: andre@0: PKIX_CHECK(pkix_SinglePolicyNode_Hashcode andre@0: (node, &nodeHash, plContext), andre@0: PKIX_SINGLEPOLICYNODEHASHCODEFAILED); andre@0: andre@0: nodeHash = 31*nodeHash + (PKIX_UInt32)(node->parent); andre@0: andre@0: PKIX_HASHCODE andre@0: (node->children, andre@0: &childrenHash, andre@0: plContext, andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: nodeHash = 31*nodeHash + childrenHash; andre@0: andre@0: *pHashcode = nodeHash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_SinglePolicyNode_Equals andre@0: * DESCRIPTION: andre@0: * andre@0: * Compares for equality the components of the PolicyNode pointed to by andre@0: * "firstPN", other than its parents and children, with those of the andre@0: * PolicyNode pointed to by "secondPN" and stores the result at "pResult" andre@0: * (PKIX_TRUE if equal; PKIX_FALSE if not). andre@0: * andre@0: * PARAMETERS: andre@0: * "firstPN" andre@0: * Address of first of the PolicyNodes to be compared; must be non-NULL andre@0: * "secondPN" andre@0: * Address of second of the PolicyNodes to be compared; must be non-NULL andre@0: * "pResult" andre@0: * Address where Boolean will be stored; must be non-NULL andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if function succeeds andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in a fatal way andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_SinglePolicyNode_Equals( andre@0: PKIX_PolicyNode *firstPN, andre@0: PKIX_PolicyNode *secondPN, andre@0: PKIX_Boolean *pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_Boolean compResult = PKIX_FALSE; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_SinglePolicyNode_Equals"); andre@0: PKIX_NULLCHECK_THREE(firstPN, secondPN, pResult); andre@0: andre@0: /* If both references are identical, they must be equal */ andre@0: if (firstPN == secondPN) { andre@0: compResult = PKIX_TRUE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* andre@0: * It seems we have to do the comparisons. Do andre@0: * the easiest ones first. andre@0: */ andre@0: if ((firstPN->criticality) != (secondPN->criticality)) { andre@0: goto cleanup; andre@0: } andre@0: if ((firstPN->depth) != (secondPN->depth)) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: PKIX_EQUALS andre@0: (firstPN->qualifierSet, andre@0: secondPN->qualifierSet, andre@0: &compResult, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (compResult == PKIX_FALSE) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* These fields must be non-NULL */ andre@0: PKIX_NULLCHECK_TWO(firstPN->validPolicy, secondPN->validPolicy); andre@0: andre@0: PKIX_EQUALS andre@0: (firstPN->validPolicy, andre@0: secondPN->validPolicy, andre@0: &compResult, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (compResult == PKIX_FALSE) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* These fields must be non-NULL */ andre@0: PKIX_NULLCHECK_TWO andre@0: (firstPN->expectedPolicySet, secondPN->expectedPolicySet); andre@0: andre@0: PKIX_EQUALS andre@0: (firstPN->expectedPolicySet, andre@0: secondPN->expectedPolicySet, andre@0: &compResult, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILEDONEXPECTEDPOLICYSETS); andre@0: andre@0: cleanup: andre@0: andre@0: *pResult = compResult; andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Equals andre@0: * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_Equals( andre@0: PKIX_PL_Object *firstObject, andre@0: PKIX_PL_Object *secondObject, andre@0: PKIX_Boolean *pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *firstPN = NULL; andre@0: PKIX_PolicyNode *secondPN = NULL; andre@0: PKIX_UInt32 secondType; andre@0: PKIX_Boolean compResult = PKIX_FALSE; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Equals"); andre@0: PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); andre@0: andre@0: /* test that firstObject is a PolicyNode */ andre@0: PKIX_CHECK(pkix_CheckType andre@0: (firstObject, PKIX_CERTPOLICYNODE_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTPOLICYNODE); andre@0: andre@0: /* andre@0: * Since we know firstObject is a PolicyNode, andre@0: * if both references are identical, they must be equal andre@0: */ andre@0: if (firstObject == secondObject){ andre@0: compResult = PKIX_TRUE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* andre@0: * If secondObject isn't a PolicyNode, we andre@0: * don't throw an error. We simply return FALSE. andre@0: */ andre@0: PKIX_CHECK(PKIX_PL_Object_GetType andre@0: (secondObject, &secondType, plContext), andre@0: PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); andre@0: andre@0: if (secondType != PKIX_CERTPOLICYNODE_TYPE) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* andre@0: * Oh, well, we have to do the comparisons. Do andre@0: * the easiest ones first. andre@0: */ andre@0: firstPN = (PKIX_PolicyNode *)firstObject; andre@0: secondPN = (PKIX_PolicyNode *)secondObject; andre@0: andre@0: /* andre@0: * We don't require the parents to be identical. In the andre@0: * course of traversing the tree, we will have checked the andre@0: * attributes of the parent nodes, and checking the lists andre@0: * of children will determine whether they match. andre@0: */ andre@0: andre@0: PKIX_EQUALS andre@0: (firstPN->children, andre@0: secondPN->children, andre@0: &compResult, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILEDONCHILDREN); andre@0: andre@0: if (compResult == PKIX_FALSE) { andre@0: goto cleanup; andre@0: } andre@0: andre@0: PKIX_CHECK(pkix_SinglePolicyNode_Equals andre@0: (firstPN, secondPN, &compResult, plContext), andre@0: PKIX_SINGLEPOLICYNODEEQUALSFAILED); andre@0: andre@0: cleanup: andre@0: andre@0: *pResult = compResult; andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_DuplicateHelper andre@0: * DESCRIPTION: andre@0: * andre@0: * Duplicates the PolicyNode whose address is pointed to by "original", andre@0: * and stores the result at "pNewNode", if a non-NULL pointer is provided andre@0: * for "pNewNode". In addition, the created PolicyNode is added as a child andre@0: * to "parent", if a non-NULL pointer is provided for "parent". Then this andre@0: * function is called recursively to duplicate each of the children of andre@0: * "original". At the top level this function is called with a null andre@0: * "parent" and a non-NULL "pNewNode". Below the top level "parent" will andre@0: * be non-NULL and "pNewNode" will be NULL. andre@0: * andre@0: * PARAMETERS: andre@0: * "original" andre@0: * Address of PolicyNode to be copied; must be non-NULL andre@0: * "parent" andre@0: * Address of PolicyNode to which the created node is to be added as a andre@0: * child; NULL for the top-level call and non-NULL below the top level andre@0: * "pNewNode" andre@0: * Address to store the node created; should be NULL if "parent" is andre@0: * non-NULL and vice versa andre@0: * "plContext" andre@0: * Platform-specific context pointer. andre@0: * THREAD SAFETY: andre@0: * Conditionally Thread Safe andre@0: * (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if function succeeds andre@0: * Returns a PolicyNode Error if the function fails in a non-fatal way. andre@0: * Returns a Fatal Error if the function fails in a fatal way andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_DuplicateHelper( andre@0: PKIX_PolicyNode *original, andre@0: PKIX_PolicyNode *parent, andre@0: PKIX_PolicyNode **pNewNode, andre@0: void *plContext) andre@0: { andre@0: PKIX_UInt32 numChildren = 0; andre@0: PKIX_UInt32 childIndex = 0; andre@0: PKIX_List *children = NULL; /* List of PKIX_PolicyNode */ andre@0: PKIX_PolicyNode *copy = NULL; andre@0: PKIX_PolicyNode *child = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_DuplicateHelper"); andre@0: andre@0: PKIX_NULLCHECK_THREE andre@0: (original, original->validPolicy, original->expectedPolicySet); andre@0: andre@0: /* andre@0: * These components are immutable, so copying the pointers andre@0: * is sufficient. The create function increments the reference andre@0: * counts as it stores the pointers into the new object. andre@0: */ andre@0: PKIX_CHECK(pkix_PolicyNode_Create andre@0: (original->validPolicy, andre@0: original->qualifierSet, andre@0: original->criticality, andre@0: original->expectedPolicySet, andre@0: ©, andre@0: plContext), andre@0: PKIX_POLICYNODECREATEFAILED); andre@0: andre@0: if (parent) { andre@0: PKIX_CHECK(pkix_PolicyNode_AddToParent(parent, copy, plContext), andre@0: PKIX_POLICYNODEADDTOPARENTFAILED); andre@0: } andre@0: andre@0: /* Are there any children to duplicate? */ andre@0: children = original->children; andre@0: andre@0: if (children) { andre@0: PKIX_CHECK(PKIX_List_GetLength(children, &numChildren, plContext), andre@0: PKIX_LISTGETLENGTHFAILED); andre@0: } andre@0: andre@0: for (childIndex = 0; childIndex < numChildren; childIndex++) { andre@0: PKIX_CHECK(PKIX_List_GetItem andre@0: (children, andre@0: childIndex, andre@0: (PKIX_PL_Object **)&child, andre@0: plContext), andre@0: PKIX_LISTGETITEMFAILED); andre@0: andre@0: PKIX_CHECK(pkix_PolicyNode_DuplicateHelper andre@0: (child, copy, NULL, plContext), andre@0: PKIX_POLICYNODEDUPLICATEHELPERFAILED); andre@0: andre@0: PKIX_DECREF(child); andre@0: } andre@0: andre@0: if (pNewNode) { andre@0: *pNewNode = copy; andre@0: copy = NULL; /* no DecRef if we give our handle away */ andre@0: } andre@0: andre@0: cleanup: andre@0: PKIX_DECREF(copy); andre@0: PKIX_DECREF(child); andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_Duplicate andre@0: * (see comments for PKIX_PL_Duplicate_Callback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_PolicyNode_Duplicate( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_Object **pNewObject, andre@0: void *plContext) andre@0: { andre@0: PKIX_PolicyNode *original = NULL; andre@0: PKIX_PolicyNode *copy = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_Duplicate"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pNewObject); andre@0: andre@0: PKIX_CHECK(pkix_CheckType andre@0: (object, PKIX_CERTPOLICYNODE_TYPE, plContext), andre@0: PKIX_OBJECTNOTPOLICYNODE); andre@0: andre@0: original = (PKIX_PolicyNode *)object; andre@0: andre@0: PKIX_CHECK(pkix_PolicyNode_DuplicateHelper andre@0: (original, NULL, ©, plContext), andre@0: PKIX_POLICYNODEDUPLICATEHELPERFAILED); andre@0: andre@0: *pNewObject = (PKIX_PL_Object *)copy; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_PolicyNode_RegisterSelf andre@0: * DESCRIPTION: andre@0: * andre@0: * Registers PKIX_CERTPOLICYNODE_TYPE and its related andre@0: * functions with systemClasses[] andre@0: * andre@0: * THREAD SAFETY: andre@0: * Not Thread Safe - for performance and complexity reasons andre@0: * andre@0: * Since this function is only called by PKIX_PL_Initialize, andre@0: * which should only be called once, it is acceptable that andre@0: * this function is not thread-safe. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_PolicyNode_RegisterSelf(void *plContext) andre@0: { andre@0: andre@0: extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; andre@0: pkix_ClassTable_Entry entry; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "pkix_PolicyNode_RegisterSelf"); andre@0: andre@0: entry.description = "PolicyNode"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_PolicyNode); andre@0: entry.destructor = pkix_PolicyNode_Destroy; andre@0: entry.equalsFunction = pkix_PolicyNode_Equals; andre@0: entry.hashcodeFunction = pkix_PolicyNode_Hashcode; andre@0: entry.toStringFunction = pkix_PolicyNode_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = pkix_PolicyNode_Duplicate; andre@0: andre@0: systemClasses[PKIX_CERTPOLICYNODE_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: andre@0: /* --Public-PolicyNode-Functions----------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetChildren andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetChildren( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_List **pChildren, /* list of PKIX_PolicyNode */ andre@0: void *plContext) andre@0: { andre@0: PKIX_List *children = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetChildren"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pChildren); andre@0: andre@0: PKIX_INCREF(node->children); andre@0: children = node->children; andre@0: andre@0: if (!children) { andre@0: PKIX_CHECK(PKIX_List_Create(&children, plContext), andre@0: PKIX_LISTCREATEFAILED); andre@0: } andre@0: andre@0: PKIX_CHECK(PKIX_List_SetImmutable(children, plContext), andre@0: PKIX_LISTSETIMMUTABLEFAILED); andre@0: andre@0: *pChildren = children; andre@0: andre@0: cleanup: andre@0: if (PKIX_ERROR_RECEIVED) { andre@0: PKIX_DECREF(children); andre@0: } andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetParent andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetParent( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_PolicyNode **pParent, andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetParent"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pParent); andre@0: andre@0: PKIX_INCREF(node->parent); andre@0: *pParent = node->parent; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetValidPolicy andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetValidPolicy( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_PL_OID **pValidPolicy, andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetValidPolicy"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pValidPolicy); andre@0: andre@0: PKIX_INCREF(node->validPolicy); andre@0: *pValidPolicy = node->validPolicy; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetPolicyQualifiers andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetPolicyQualifiers( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_List **pQualifiers, /* list of PKIX_PL_CertPolicyQualifier */ andre@0: void *plContext) andre@0: { andre@0: PKIX_List *qualifiers = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetPolicyQualifiers"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pQualifiers); andre@0: andre@0: PKIX_INCREF(node->qualifierSet); andre@0: qualifiers = node->qualifierSet; andre@0: andre@0: if (!qualifiers) { andre@0: PKIX_CHECK(PKIX_List_Create(&qualifiers, plContext), andre@0: PKIX_LISTCREATEFAILED); andre@0: } andre@0: andre@0: PKIX_CHECK(PKIX_List_SetImmutable(qualifiers, plContext), andre@0: PKIX_LISTSETIMMUTABLEFAILED); andre@0: andre@0: *pQualifiers = qualifiers; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetExpectedPolicies andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetExpectedPolicies( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_List **pExpPolicies, /* list of PKIX_PL_OID */ andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetExpectedPolicies"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pExpPolicies); andre@0: andre@0: PKIX_INCREF(node->expectedPolicySet); andre@0: *pExpPolicies = node->expectedPolicySet; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_IsCritical andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_IsCritical( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_Boolean *pCritical, andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_IsCritical"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pCritical); andre@0: andre@0: *pCritical = node->criticality; andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PolicyNode_GetDepth andre@0: * (see description of this function in pkix_results.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PolicyNode_GetDepth( andre@0: PKIX_PolicyNode *node, andre@0: PKIX_UInt32 *pDepth, andre@0: void *plContext) andre@0: { andre@0: andre@0: PKIX_ENTER(CERTPOLICYNODE, "PKIX_PolicyNode_GetDepth"); andre@0: andre@0: PKIX_NULLCHECK_TWO(node, pDepth); andre@0: andre@0: *pDepth = node->depth; andre@0: andre@0: PKIX_RETURN(CERTPOLICYNODE); andre@0: }