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_valresult.c andre@0: * andre@0: * ValidateResult Object Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_valresult.h" andre@0: andre@0: /* --Private-Functions-------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateResult_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateResult *result = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATERESULT, "pkix_ValidateResult_Destroy"); andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: /* Check that this object is a validate result object */ andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATERESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATERESULT); andre@0: andre@0: result = (PKIX_ValidateResult *)object; andre@0: andre@0: PKIX_DECREF(result->anchor); andre@0: PKIX_DECREF(result->pubKey); andre@0: PKIX_DECREF(result->policyTree); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_Equals andre@0: * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateResult_Equals( andre@0: PKIX_PL_Object *first, andre@0: PKIX_PL_Object *second, andre@0: PKIX_Boolean *pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_UInt32 secondType; andre@0: PKIX_Boolean cmpResult; andre@0: PKIX_ValidateResult *firstValResult = NULL; andre@0: PKIX_ValidateResult *secondValResult = NULL; andre@0: PKIX_TrustAnchor *firstAnchor = NULL; andre@0: PKIX_TrustAnchor *secondAnchor = NULL; andre@0: PKIX_PolicyNode *firstTree = NULL; andre@0: PKIX_PolicyNode *secondTree = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATERESULT, "pkix_ValidateResult_Equals"); andre@0: PKIX_NULLCHECK_THREE(first, second, pResult); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(first, PKIX_VALIDATERESULT_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTVALIDATERESULT); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_GetType(second, &secondType, plContext), andre@0: PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); andre@0: andre@0: *pResult = PKIX_FALSE; andre@0: andre@0: if (secondType != PKIX_VALIDATERESULT_TYPE) goto cleanup; andre@0: andre@0: firstValResult = (PKIX_ValidateResult *)first; andre@0: secondValResult = (PKIX_ValidateResult *)second; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstValResult->pubKey, andre@0: (PKIX_PL_Object *)secondValResult->pubKey, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (!cmpResult) goto cleanup; andre@0: andre@0: firstAnchor = firstValResult->anchor; andre@0: secondAnchor = secondValResult->anchor; andre@0: andre@0: if ((firstAnchor != NULL) && (secondAnchor != NULL)) { andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstAnchor, andre@0: (PKIX_PL_Object *)secondAnchor, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: } else { andre@0: cmpResult = (firstAnchor == secondAnchor); andre@0: } andre@0: andre@0: if (!cmpResult) goto cleanup; andre@0: andre@0: firstTree = firstValResult->policyTree; andre@0: secondTree = secondValResult->policyTree; andre@0: andre@0: if ((firstTree != NULL) && (secondTree != NULL)) { andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstTree, andre@0: (PKIX_PL_Object *)secondTree, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: } else { andre@0: cmpResult = (firstTree == secondTree); andre@0: } andre@0: andre@0: *pResult = cmpResult; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateResult_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateResult *valResult = NULL; andre@0: PKIX_UInt32 hash = 0; andre@0: PKIX_UInt32 pubKeyHash = 0; andre@0: PKIX_UInt32 anchorHash = 0; andre@0: PKIX_UInt32 policyTreeHash = 0; andre@0: andre@0: PKIX_ENTER(VALIDATERESULT, "pkix_ValidateResult_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATERESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATERESULT); andre@0: andre@0: valResult = (PKIX_ValidateResult*)object; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)valResult->pubKey, &pubKeyHash, plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: if (valResult->anchor) { andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)valResult->anchor, andre@0: &anchorHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: } andre@0: andre@0: if (valResult->policyTree) { andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)valResult->policyTree, andre@0: &policyTreeHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: } andre@0: andre@0: hash = 31*(31 * pubKeyHash + anchorHash) + policyTreeHash; andre@0: andre@0: *pHashcode = hash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateResult_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateResult *valResult = NULL; andre@0: PKIX_PL_String *formatString = NULL; andre@0: PKIX_PL_String *valResultString = NULL; andre@0: andre@0: PKIX_TrustAnchor *anchor = NULL; andre@0: PKIX_PL_PublicKey *pubKey = NULL; andre@0: PKIX_PolicyNode *policyTree = NULL; andre@0: andre@0: PKIX_PL_String *anchorString = NULL; andre@0: PKIX_PL_String *pubKeyString = NULL; andre@0: PKIX_PL_String *treeString = NULL; andre@0: char *asciiNullString = "(null)"; andre@0: char *asciiFormat = andre@0: "[\n" andre@0: "\tTrustAnchor: \t\t%s" andre@0: "\tPubKey: \t\t%s\n" andre@0: "\tPolicyTree: \t\t%s\n" andre@0: "]\n"; andre@0: andre@0: PKIX_ENTER(VALIDATERESULT, "pkix_ValidateResult_ToString"); andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATERESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATERESULT); andre@0: andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, asciiFormat, 0, &formatString, plContext), andre@0: PKIX_STRINGCREATEFAILED); andre@0: andre@0: valResult = (PKIX_ValidateResult*)object; andre@0: andre@0: anchor = valResult->anchor; andre@0: andre@0: if (anchor) { andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)anchor, &anchorString, plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: } else { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: asciiNullString, andre@0: 0, andre@0: &anchorString, andre@0: plContext), andre@0: PKIX_STRINGCREATEFAILED); andre@0: } andre@0: andre@0: pubKey = valResult->pubKey; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)pubKey, &pubKeyString, plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: policyTree = valResult->policyTree; andre@0: andre@0: if (policyTree) { andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)policyTree, &treeString, plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: } else { andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: asciiNullString, andre@0: 0, andre@0: &treeString, andre@0: plContext), andre@0: PKIX_STRINGCREATEFAILED); andre@0: } andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&valResultString, andre@0: plContext, andre@0: formatString, andre@0: anchorString, andre@0: pubKeyString, andre@0: treeString), andre@0: PKIX_SPRINTFFAILED); andre@0: andre@0: *pString = valResultString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(formatString); andre@0: PKIX_DECREF(anchorString); andre@0: PKIX_DECREF(pubKeyString); andre@0: PKIX_DECREF(treeString); andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_VALIDATERESULT_TYPE and its related functions with andre@0: * systemClasses[] 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, which should andre@0: * only be called once, it is acceptable that this function is not andre@0: * thread-safe. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_ValidateResult_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(VALIDATERESULT, "pkix_ValidateResult_RegisterSelf"); andre@0: andre@0: entry.description = "ValidateResult"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_ValidateResult); andre@0: entry.destructor = pkix_ValidateResult_Destroy; andre@0: entry.equalsFunction = pkix_ValidateResult_Equals; andre@0: entry.hashcodeFunction = pkix_ValidateResult_Hashcode; andre@0: entry.toStringFunction = pkix_ValidateResult_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = pkix_duplicateImmutable; andre@0: andre@0: systemClasses[PKIX_VALIDATERESULT_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateResult_Create andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a new ValidateResult Object using the PublicKey pointed to by andre@0: * "pubKey", the TrustAnchor pointed to by "anchor", and the PolicyNode andre@0: * pointed to by "policyTree", and stores it at "pResult". andre@0: * andre@0: * PARAMETERS andre@0: * "pubKey" andre@0: * PublicKey of the desired ValidateResult. Must be non-NULL. andre@0: * "anchor" andre@0: * TrustAnchor of the desired Validateresult. May be NULL. andre@0: * "policyTree" andre@0: * PolicyNode of the desired ValidateResult; may be NULL andre@0: * "pResult" 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: * 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 Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_ValidateResult_Create( andre@0: PKIX_PL_PublicKey *pubKey, andre@0: PKIX_TrustAnchor *anchor, andre@0: PKIX_PolicyNode *policyTree, andre@0: PKIX_ValidateResult **pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateResult *result = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATERESULT, "pkix_ValidateResult_Create"); andre@0: PKIX_NULLCHECK_TWO(pubKey, pResult); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_VALIDATERESULT_TYPE, andre@0: sizeof (PKIX_ValidateResult), andre@0: (PKIX_PL_Object **)&result, andre@0: plContext), andre@0: PKIX_COULDNOTCREATEVALIDATERESULTOBJECT); andre@0: andre@0: /* initialize fields */ andre@0: andre@0: PKIX_INCREF(pubKey); andre@0: result->pubKey = pubKey; andre@0: andre@0: PKIX_INCREF(anchor); andre@0: result->anchor = anchor; andre@0: andre@0: PKIX_INCREF(policyTree); andre@0: result->policyTree = policyTree; andre@0: andre@0: *pResult = result; andre@0: result = NULL; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(result); andre@0: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: andre@0: } andre@0: andre@0: /* --Public-Functions--------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateResult_GetPublicKey andre@0: * (see comments in pkix_result.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateResult_GetPublicKey( andre@0: PKIX_ValidateResult *result, andre@0: PKIX_PL_PublicKey **pPublicKey, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(VALIDATERESULT, "PKIX_ValidateResult_GetPublicKey"); andre@0: PKIX_NULLCHECK_TWO(result, pPublicKey); andre@0: andre@0: PKIX_INCREF(result->pubKey); andre@0: *pPublicKey = result->pubKey; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateResult_GetTrustAnchor andre@0: * (see comments in pkix_result.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateResult_GetTrustAnchor( andre@0: PKIX_ValidateResult *result, andre@0: PKIX_TrustAnchor **pTrustAnchor, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(VALIDATERESULT, "PKIX_ValidateResult_GetTrustAnchor"); andre@0: PKIX_NULLCHECK_TWO(result, pTrustAnchor); andre@0: andre@0: PKIX_INCREF(result->anchor); andre@0: *pTrustAnchor = result->anchor; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateResult_GetPolicyTree andre@0: * (see comments in pkix_result.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateResult_GetPolicyTree( andre@0: PKIX_ValidateResult *result, andre@0: PKIX_PolicyNode **pPolicyTree, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(VALIDATERESULT, "PKIX_ValidateResult_GetPolicyTree"); andre@0: PKIX_NULLCHECK_TWO(result, pPolicyTree); andre@0: andre@0: PKIX_INCREF(result->policyTree); andre@0: (*pPolicyTree) = result->policyTree; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(VALIDATERESULT); andre@0: }