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_pl_certpolicyinfo.c andre@0: * andre@0: * CertPolicyInfo Type Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_pl_certpolicyinfo.h" andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_Create andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a new CertPolicyInfo Object using the OID pointed to by "oid" and andre@0: * the List of CertPolicyQualifiers pointed to by "qualifiers", and stores it andre@0: * at "pObject". If a non-NULL list is provided, the caller is expected to andre@0: * have already set it to be immutable. The caller may provide an empty List, andre@0: * but a NULL List is preferable so a user does not need to call andre@0: * List_GetLength to get the number of qualifiers. andre@0: * andre@0: * PARAMETERS andre@0: * "oid" andre@0: * OID of the desired PolicyInfo ID; must be non-NULL andre@0: * "qualifiers" andre@0: * List of CertPolicyQualifiers; may be NULL or empty andre@0: * "pObject" 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_pl_CertPolicyInfo_Create( andre@0: PKIX_PL_OID *oid, andre@0: PKIX_List *qualifiers, andre@0: PKIX_PL_CertPolicyInfo **pObject, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyInfo *policyInfo = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_Create"); andre@0: andre@0: PKIX_NULLCHECK_TWO(oid, pObject); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_CERTPOLICYINFO_TYPE, andre@0: sizeof (PKIX_PL_CertPolicyInfo), andre@0: (PKIX_PL_Object **)&policyInfo, andre@0: plContext), andre@0: PKIX_COULDNOTCREATECERTPOLICYINFOOBJECT); andre@0: andre@0: PKIX_INCREF(oid); andre@0: policyInfo->cpID = oid; andre@0: andre@0: PKIX_INCREF(qualifiers); andre@0: policyInfo->policyQualifiers = qualifiers; andre@0: andre@0: *pObject = policyInfo; andre@0: policyInfo = NULL; andre@0: andre@0: cleanup: andre@0: PKIX_DECREF(policyInfo); andre@0: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_Destroy andre@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_pl_CertPolicyInfo_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyInfo *certPI = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_Destroy"); andre@0: andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYINFO_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYINFO); andre@0: andre@0: certPI = (PKIX_PL_CertPolicyInfo*)object; andre@0: andre@0: PKIX_DECREF(certPI->cpID); andre@0: PKIX_DECREF(certPI->policyQualifiers); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_ToString andre@0: * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_pl_CertPolicyInfo_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyInfo *certPI = NULL; andre@0: PKIX_PL_String *oidString = NULL; andre@0: PKIX_PL_String *listString = NULL; andre@0: PKIX_PL_String *format = NULL; andre@0: PKIX_PL_String *outString = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_ToString"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYINFO_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYINFO); andre@0: andre@0: certPI = (PKIX_PL_CertPolicyInfo *)object; andre@0: andre@0: PKIX_NULLCHECK_ONE(certPI->cpID); andre@0: andre@0: PKIX_TOSTRING andre@0: (certPI->cpID, andre@0: &oidString, andre@0: plContext, andre@0: PKIX_OIDTOSTRINGFAILED); andre@0: andre@0: PKIX_TOSTRING andre@0: (certPI->policyQualifiers, andre@0: &listString, andre@0: plContext, andre@0: PKIX_LISTTOSTRINGFAILED); andre@0: andre@0: /* Put them together in the form OID[Qualifiers] */ andre@0: PKIX_CHECK(PKIX_PL_String_Create andre@0: (PKIX_ESCASCII, "%s[%s]", 0, &format, plContext), andre@0: PKIX_ERRORINSTRINGCREATE); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Sprintf andre@0: (&outString, plContext, format, oidString, listString), andre@0: PKIX_ERRORINSPRINTF); andre@0: andre@0: *pString = outString; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_DECREF(oidString); andre@0: PKIX_DECREF(listString); andre@0: PKIX_DECREF(format); andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_Hashcode andre@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) andre@0: */ andre@0: static PKIX_Error * andre@0: pkix_pl_CertPolicyInfo_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyInfo *certPI = NULL; andre@0: PKIX_UInt32 oidHash = 0; andre@0: PKIX_UInt32 listHash = 0; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_Hashcode"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYINFO_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYINFO); andre@0: andre@0: certPI = (PKIX_PL_CertPolicyInfo *)object; andre@0: andre@0: PKIX_NULLCHECK_ONE(certPI->cpID); andre@0: andre@0: PKIX_HASHCODE andre@0: (certPI->cpID, andre@0: &oidHash, andre@0: plContext, andre@0: PKIX_ERRORINOIDHASHCODE); andre@0: andre@0: PKIX_HASHCODE andre@0: (certPI->policyQualifiers, andre@0: &listHash, andre@0: plContext, andre@0: PKIX_ERRORINLISTHASHCODE); andre@0: andre@0: *pHashcode = (31 * oidHash) + listHash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_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_pl_CertPolicyInfo_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_PL_CertPolicyInfo *firstCPI = NULL; andre@0: PKIX_PL_CertPolicyInfo *secondCPI = NULL; andre@0: PKIX_UInt32 secondType = 0; andre@0: PKIX_Boolean compare = PKIX_FALSE; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_Equals"); andre@0: PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); andre@0: andre@0: /* test that firstObject is a CertPolicyInfo */ andre@0: PKIX_CHECK(pkix_CheckType andre@0: (firstObject, PKIX_CERTPOLICYINFO_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTCERTPOLICYINFO); andre@0: andre@0: /* andre@0: * Since we know firstObject is a CertPolicyInfo, andre@0: * if both references are identical, they must be equal andre@0: */ andre@0: if (firstObject == secondObject){ andre@0: *pResult = PKIX_TRUE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: /* andre@0: * If secondObject isn't a CertPolicyInfo, 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: if (secondType != PKIX_CERTPOLICYINFO_TYPE) { andre@0: *pResult = PKIX_FALSE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: firstCPI = (PKIX_PL_CertPolicyInfo *)firstObject; andre@0: secondCPI = (PKIX_PL_CertPolicyInfo *)secondObject; andre@0: andre@0: /* andre@0: * Compare the value of the OID components andre@0: */ andre@0: andre@0: PKIX_NULLCHECK_TWO(firstCPI->cpID, secondCPI->cpID); andre@0: andre@0: PKIX_EQUALS andre@0: (firstCPI->cpID, andre@0: secondCPI->cpID, andre@0: &compare, andre@0: plContext, andre@0: PKIX_OIDEQUALSFAILED); andre@0: andre@0: /* andre@0: * If the OIDs did not match, we don't need to andre@0: * compare the Lists. If the OIDs did match, andre@0: * the return value is the value of the andre@0: * List comparison. andre@0: */ andre@0: if (compare) { andre@0: PKIX_EQUALS andre@0: (firstCPI->policyQualifiers, andre@0: secondCPI->policyQualifiers, andre@0: &compare, andre@0: plContext, andre@0: PKIX_LISTEQUALSFAILED); andre@0: } andre@0: andre@0: *pResult = compare; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyInfo_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_CERTPOLICYINFO_TYPE and its related andre@0: * functions with 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, 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_pl_CertPolicyInfo_RegisterSelf(void *plContext) andre@0: { andre@0: extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; andre@0: pkix_ClassTable_Entry entry; andre@0: andre@0: PKIX_ENTER(CERTPOLICYINFO, "pkix_pl_CertPolicyInfo_RegisterSelf"); andre@0: andre@0: entry.description = "CertPolicyInfo"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_PL_CertPolicyInfo); andre@0: entry.destructor = pkix_pl_CertPolicyInfo_Destroy; andre@0: entry.equalsFunction = pkix_pl_CertPolicyInfo_Equals; andre@0: entry.hashcodeFunction = pkix_pl_CertPolicyInfo_Hashcode; andre@0: entry.toStringFunction = pkix_pl_CertPolicyInfo_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = pkix_duplicateImmutable; andre@0: andre@0: systemClasses[PKIX_CERTPOLICYINFO_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* --Public-CertPolicyInfo-Functions------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_CertPolicyInfo_GetPolicyId andre@0: * (see comments in pkix_pl_pki.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_CertPolicyInfo_GetPolicyId( andre@0: PKIX_PL_CertPolicyInfo *policyInfo, andre@0: PKIX_PL_OID **pPolicyId, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(CERTPOLICYINFO, "PKIX_PL_CertPolicyInfo_GetPolicyId"); andre@0: andre@0: PKIX_NULLCHECK_TWO(policyInfo, pPolicyId); andre@0: andre@0: PKIX_INCREF(policyInfo->cpID); andre@0: andre@0: *pPolicyId = policyInfo->cpID; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_CertPolicyInfo_GetPolQualifiers andre@0: * (see comments in pkix_pl_pki.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_CertPolicyInfo_GetPolQualifiers( andre@0: PKIX_PL_CertPolicyInfo *policyInfo, andre@0: PKIX_List **pQuals, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER(CERTPOLICYINFO, "PKIX_PL_CertPolicyInfo_GetPolQualifiers"); andre@0: andre@0: PKIX_NULLCHECK_TWO(policyInfo, pQuals); andre@0: andre@0: PKIX_INCREF(policyInfo->policyQualifiers); andre@0: andre@0: /* andre@0: * This List is created in PKIX_PL_Cert_DecodePolicyInfo andre@0: * and is set immutable immediately after being created. andre@0: */ andre@0: *pQuals = policyInfo->policyQualifiers; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYINFO); andre@0: }