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_valparams.c andre@0: * andre@0: * Validate Params Object Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_valparams.h" andre@0: andre@0: /* --Private-Functions-------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateParams_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateParams_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateParams *params = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATEPARAMS, "pkix_ValidateParams_Destroy"); andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: /* Check that this object is a validate params object */ andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATEPARAMS_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATEPARAMS); andre@0: andre@0: params = (PKIX_ValidateParams *)object; andre@0: andre@0: PKIX_DECREF(params->procParams); andre@0: PKIX_DECREF(params->chain); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateParams_Equals andre@0: * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateParams_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_ValidateParams *firstValParams = NULL; andre@0: PKIX_ValidateParams *secondValParams = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATEPARAMS, "pkix_ValidateParams_Equals"); andre@0: PKIX_NULLCHECK_THREE(first, second, pResult); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(first, PKIX_VALIDATEPARAMS_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTVALIDATEPARAMS); 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_VALIDATEPARAMS_TYPE) goto cleanup; andre@0: andre@0: firstValParams = (PKIX_ValidateParams *)first; andre@0: secondValParams = (PKIX_ValidateParams *)second; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Equals andre@0: ((PKIX_PL_Object *)firstValParams->procParams, andre@0: (PKIX_PL_Object *)secondValParams->procParams, 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 *)firstValParams->chain, andre@0: (PKIX_PL_Object *)secondValParams->chain, andre@0: &cmpResult, andre@0: plContext), andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (!cmpResult) goto cleanup; andre@0: andre@0: *pResult = cmpResult; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateParams_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateParams_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateParams *valParams = NULL; andre@0: PKIX_UInt32 hash = 0; andre@0: PKIX_UInt32 procParamsHash = 0; andre@0: PKIX_UInt32 chainHash = 0; andre@0: andre@0: PKIX_ENTER(VALIDATEPARAMS, "pkix_ValidateParams_Hashcode"); andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATEPARAMS_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATEPARAMS); andre@0: andre@0: valParams = (PKIX_ValidateParams*)object; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)valParams->procParams, andre@0: &procParamsHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Hashcode andre@0: ((PKIX_PL_Object *)valParams->chain, andre@0: &chainHash, andre@0: plContext), andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: hash = 31 * procParamsHash + chainHash; andre@0: andre@0: *pHashcode = hash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateParams_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_ValidateParams_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateParams *valParams = NULL; andre@0: char *asciiFormat = NULL; andre@0: PKIX_PL_String *formatString = NULL; andre@0: PKIX_PL_String *valParamsString = NULL; andre@0: andre@0: PKIX_PL_String *procParamsString = NULL; andre@0: PKIX_PL_String *chainString = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATEPARAMS, "pkix_ValidateParams_ToString"); andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_VALIDATEPARAMS_TYPE, plContext), andre@0: PKIX_OBJECTNOTVALIDATEPARAMS); andre@0: andre@0: asciiFormat = andre@0: "[\n" andre@0: "\tProcessing Params: \n" andre@0: "\t********BEGIN PROCESSING PARAMS********\n" andre@0: "\t\t%s\n" andre@0: "\t********END PROCESSING PARAMS********\n" andre@0: "\tChain: \t\t%s\n" andre@0: "]\n"; andre@0: andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, andre@0: asciiFormat, andre@0: 0, andre@0: &formatString, andre@0: plContext), andre@0: PKIX_STRINGCREATEFAILED); andre@0: andre@0: valParams = (PKIX_ValidateParams*)object; andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object*)valParams->procParams, andre@0: &procParamsString, andre@0: plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_ToString andre@0: ((PKIX_PL_Object *)valParams->chain, andre@0: &chainString, andre@0: plContext), andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&valParamsString, andre@0: plContext, andre@0: formatString, andre@0: procParamsString, andre@0: chainString), andre@0: PKIX_SPRINTFFAILED); andre@0: andre@0: *pString = valParamsString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(formatString); andre@0: PKIX_DECREF(procParamsString); andre@0: PKIX_DECREF(chainString); andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_ValidateParams_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_VALIDATEPARAMS_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_ValidateParams_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(VALIDATEPARAMS, "pkix_ValidateParams_RegisterSelf"); andre@0: andre@0: entry.description = "ValidateParams"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_ValidateParams); andre@0: entry.destructor = pkix_ValidateParams_Destroy; andre@0: entry.equalsFunction = pkix_ValidateParams_Equals; andre@0: entry.hashcodeFunction = pkix_ValidateParams_Hashcode; andre@0: entry.toStringFunction = pkix_ValidateParams_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = NULL; andre@0: andre@0: systemClasses[PKIX_VALIDATEPARAMS_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* --Public-Functions--------------------------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateParams_Create (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateParams_Create( andre@0: PKIX_ProcessingParams *procParams, andre@0: PKIX_List *chain, andre@0: PKIX_ValidateParams **pParams, andre@0: void *plContext) andre@0: { andre@0: PKIX_ValidateParams *params = NULL; andre@0: andre@0: PKIX_ENTER(VALIDATEPARAMS, "PKIX_ValidateParams_Create"); andre@0: PKIX_NULLCHECK_THREE(procParams, chain, pParams); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_VALIDATEPARAMS_TYPE, andre@0: sizeof (PKIX_ValidateParams), andre@0: (PKIX_PL_Object **)¶ms, andre@0: plContext), andre@0: PKIX_COULDNOTCREATEVALIDATEPARAMSOBJECT); andre@0: andre@0: /* initialize fields */ andre@0: PKIX_INCREF(procParams); andre@0: params->procParams = procParams; andre@0: andre@0: PKIX_INCREF(chain); andre@0: params->chain = chain; andre@0: andre@0: *pParams = params; andre@0: params = NULL; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(params); andre@0: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateParams_GetProcessingParams andre@0: * (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateParams_GetProcessingParams( andre@0: PKIX_ValidateParams *valParams, andre@0: PKIX_ProcessingParams **pProcParams, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(VALIDATEPARAMS, "PKIX_ValidateParams_GetProcessingParams"); andre@0: PKIX_NULLCHECK_TWO(valParams, pProcParams); andre@0: andre@0: PKIX_INCREF(valParams->procParams); andre@0: andre@0: *pProcParams = valParams->procParams; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_ValidateParams_GetCertChain (see comments in pkix_params.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_ValidateParams_GetCertChain( andre@0: PKIX_ValidateParams *valParams, andre@0: PKIX_List **pChain, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(VALIDATEPARAMS, "PKIX_ValidateParams_GetCertChain"); andre@0: PKIX_NULLCHECK_TWO(valParams, pChain); andre@0: andre@0: PKIX_INCREF(valParams->chain); andre@0: andre@0: *pChain = valParams->chain; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(VALIDATEPARAMS); andre@0: }