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_buildresult.c andre@0: * andre@0: * BuildResult Object Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_buildresult.h" andre@0: andre@0: /* --Private-Functions-------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_BuildResult_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_BuildResult *result = NULL; andre@0: andre@0: PKIX_ENTER(BUILDRESULT, "pkix_BuildResult_Destroy"); andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: /* Check that this object is a build result object */ andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_BUILDRESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTBUILDRESULT); andre@0: andre@0: result = (PKIX_BuildResult *)object; andre@0: andre@0: PKIX_DECREF(result->valResult); andre@0: PKIX_DECREF(result->certChain); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_Equals andre@0: * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_BuildResult_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_BuildResult *firstBuildResult = NULL; andre@0: PKIX_BuildResult *secondBuildResult = NULL; andre@0: andre@0: PKIX_ENTER(BUILDRESULT, "pkix_BuildResult_Equals"); andre@0: PKIX_NULLCHECK_THREE(first, second, pResult); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(first, PKIX_BUILDRESULT_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTBUILDRESULT); 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_BUILDRESULT_TYPE) goto cleanup; andre@0: andre@0: firstBuildResult = (PKIX_BuildResult *)first; andre@0: secondBuildResult = (PKIX_BuildResult *)second; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstBuildResult->valResult, andre@0: (PKIX_PL_Object *)secondBuildResult->valResult, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (!cmpResult) goto cleanup; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstBuildResult->certChain, andre@0: (PKIX_PL_Object *)secondBuildResult->certChain, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (!cmpResult) goto cleanup; andre@0: andre@0: /* andre@0: * The remaining case is that both are null, andre@0: * which we consider equality. andre@0: * cmpResult = PKIX_TRUE; andre@0: */ andre@0: andre@0: *pResult = cmpResult; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_BuildResult_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_BuildResult *buildResult = NULL; andre@0: PKIX_UInt32 hash = 0; andre@0: PKIX_UInt32 valResultHash = 0; andre@0: PKIX_UInt32 certChainHash = 0; andre@0: andre@0: PKIX_ENTER(BUILDRESULT, "pkix_BuildResult_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_BUILDRESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTBUILDRESULT); andre@0: andre@0: buildResult = (PKIX_BuildResult*)object; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)buildResult->valResult, andre@0: &valResultHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)buildResult->certChain, andre@0: &certChainHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: hash = 31*(31 * valResultHash + certChainHash); andre@0: andre@0: *pHashcode = hash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_BuildResult_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_BuildResult *buildResult = NULL; andre@0: PKIX_PL_String *formatString = NULL; andre@0: PKIX_PL_String *buildResultString = NULL; andre@0: andre@0: PKIX_ValidateResult *valResult = NULL; andre@0: PKIX_List *certChain = NULL; andre@0: andre@0: PKIX_PL_String *valResultString = NULL; andre@0: PKIX_PL_String *certChainString = NULL; andre@0: andre@0: char *asciiFormat = andre@0: "[\n" andre@0: "\tValidateResult: \t\t%s" andre@0: "\tCertChain: \t\t%s\n" andre@0: "]\n"; andre@0: andre@0: PKIX_ENTER(BUILDRESULT, "pkix_BuildResult_ToString"); andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_BUILDRESULT_TYPE, plContext), andre@0: PKIX_OBJECTNOTBUILDRESULT); andre@0: andre@0: buildResult = (PKIX_BuildResult*)object; andre@0: andre@0: valResult = buildResult->valResult; 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: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)valResult, &valResultString, plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: certChain = buildResult->certChain; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)certChain, &certChainString, plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&buildResultString, andre@0: plContext, andre@0: formatString, andre@0: valResultString, andre@0: certChainString), andre@0: PKIX_SPRINTFFAILED); andre@0: andre@0: *pString = buildResultString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(formatString); andre@0: PKIX_DECREF(valResultString); andre@0: PKIX_DECREF(certChainString); andre@0: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_BUILDRESULT_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_BuildResult_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(BUILDRESULT, "pkix_BuildResult_RegisterSelf"); andre@0: andre@0: entry.description = "BuildResult"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_BuildResult); andre@0: entry.destructor = pkix_BuildResult_Destroy; andre@0: entry.equalsFunction = pkix_BuildResult_Equals; andre@0: entry.hashcodeFunction = pkix_BuildResult_Hashcode; andre@0: entry.toStringFunction = pkix_BuildResult_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = pkix_duplicateImmutable; andre@0: andre@0: systemClasses[PKIX_BUILDRESULT_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_BuildResult_Create andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a new BuildResult Object using the ValidateResult pointed to by andre@0: * "valResult" and the List pointed to by "certChain", and stores it at andre@0: * "pResult". andre@0: * andre@0: * PARAMETERS andre@0: * "valResult" andre@0: * Address of ValidateResult component. Must be non-NULL. andre@0: * "certChain andre@0: * Address of List component. Must be non-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_BuildResult_Create( andre@0: PKIX_ValidateResult *valResult, andre@0: PKIX_List *certChain, andre@0: PKIX_BuildResult **pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_BuildResult *result = NULL; andre@0: andre@0: PKIX_ENTER(BUILDRESULT, "pkix_BuildResult_Create"); andre@0: PKIX_NULLCHECK_THREE(valResult, certChain, pResult); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_BUILDRESULT_TYPE, andre@0: sizeof (PKIX_BuildResult), andre@0: (PKIX_PL_Object **)&result, andre@0: plContext), andre@0: PKIX_COULDNOTCREATEBUILDRESULTOBJECT); andre@0: andre@0: /* initialize fields */ andre@0: andre@0: PKIX_INCREF(valResult); andre@0: result->valResult = valResult; andre@0: andre@0: PKIX_INCREF(certChain); andre@0: result->certChain = certChain; andre@0: andre@0: PKIX_CHECK(PKIX_List_SetImmutable(result->certChain, plContext), andre@0: PKIX_LISTSETIMMUTABLEFAILED); 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(BUILDRESULT); andre@0: andre@0: } andre@0: andre@0: /* --Public-Functions--------------------------------------------- */ andre@0: andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_BuildResult_GetValidateResult andre@0: * (see comments in pkix_result.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_BuildResult_GetValidateResult( andre@0: PKIX_BuildResult *result, andre@0: PKIX_ValidateResult **pResult, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(BUILDRESULT, "PKIX_BuildResult_GetValidateResult"); andre@0: PKIX_NULLCHECK_TWO(result, pResult); andre@0: andre@0: PKIX_INCREF(result->valResult); andre@0: *pResult = result->valResult; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: } andre@0: andre@0: andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_BuildResult_GetCertChain andre@0: * (see comments in pkix_result.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_BuildResult_GetCertChain( andre@0: PKIX_BuildResult *result, andre@0: PKIX_List **pChain, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(BUILDRESULT, "PKIX_BuildResult_GetCertChain"); andre@0: PKIX_NULLCHECK_TWO(result, pChain); andre@0: andre@0: PKIX_INCREF(result->certChain); andre@0: *pChain = result->certChain; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(BUILDRESULT); andre@0: }