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_certpolicymap.c andre@0: * andre@0: * CertPolicyMap Type Functions andre@0: * andre@0: */ andre@0: andre@0: #include "pkix_pl_certpolicymap.h" andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_Create andre@0: * DESCRIPTION: andre@0: * andre@0: * Creates a new CertPolicyMap Object pairing the OID given by andre@0: * "issuerDomainPolicy" with the OID given by "subjectDomainPolicy", and andre@0: * stores the result at "pCertPolicyMap". andre@0: * andre@0: * PARAMETERS andre@0: * "issuerDomainPolicy" andre@0: * Address of the OID of the IssuerDomainPolicy. Must be non-NULL. andre@0: * "subjectDomainPolicy" andre@0: * Address of the OID of the SubjectDomainPolicy. Must be non-NULL. andre@0: * "pCertPolicyMap" andre@0: * Address where CertPolicyMap 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 CertPolicyMap 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_pl_CertPolicyMap_Create( andre@0: PKIX_PL_OID *issuerDomainPolicy, andre@0: PKIX_PL_OID *subjectDomainPolicy, andre@0: PKIX_PL_CertPolicyMap **pCertPolicyMap, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyMap *policyMap = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_Create"); andre@0: andre@0: PKIX_NULLCHECK_THREE andre@0: (issuerDomainPolicy, subjectDomainPolicy, pCertPolicyMap); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Object_Alloc andre@0: (PKIX_CERTPOLICYMAP_TYPE, andre@0: sizeof (PKIX_PL_CertPolicyMap), andre@0: (PKIX_PL_Object **)&policyMap, andre@0: plContext), andre@0: PKIX_COULDNOTCREATECERTPOLICYMAPOBJECT); andre@0: andre@0: PKIX_INCREF(issuerDomainPolicy); andre@0: policyMap->issuerDomainPolicy = issuerDomainPolicy; andre@0: andre@0: PKIX_INCREF(subjectDomainPolicy); andre@0: policyMap->subjectDomainPolicy = subjectDomainPolicy; andre@0: andre@0: *pCertPolicyMap = policyMap; andre@0: policyMap = NULL; andre@0: andre@0: cleanup: andre@0: PKIX_DECREF(policyMap); andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_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_CertPolicyMap_Destroy( andre@0: PKIX_PL_Object *object, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyMap *certMap = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_Destroy"); andre@0: andre@0: PKIX_NULLCHECK_ONE(object); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYMAP_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYMAP); andre@0: andre@0: certMap = (PKIX_PL_CertPolicyMap*)object; andre@0: andre@0: PKIX_DECREF(certMap->issuerDomainPolicy); andre@0: PKIX_DECREF(certMap->subjectDomainPolicy); andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_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_CertPolicyMap_ToString( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_String **pString, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyMap *certMap = NULL; andre@0: PKIX_PL_String *format = NULL; andre@0: PKIX_PL_String *outString = NULL; andre@0: PKIX_PL_String *issuerString = NULL; andre@0: PKIX_PL_String *subjectString = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_ToString"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pString); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYMAP_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYMAP); andre@0: andre@0: certMap = (PKIX_PL_CertPolicyMap *)object; andre@0: andre@0: PKIX_TOSTRING andre@0: (certMap->issuerDomainPolicy, andre@0: &issuerString, andre@0: plContext, andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: PKIX_TOSTRING andre@0: (certMap->subjectDomainPolicy, andre@0: &subjectString, andre@0: plContext, andre@0: PKIX_OBJECTTOSTRINGFAILED); andre@0: andre@0: /* Put them together in the form issuerPolicy=>subjectPolicy */ 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, issuerString, subjectString), andre@0: PKIX_ERRORINSPRINTF); andre@0: andre@0: *pString = outString; andre@0: andre@0: cleanup: andre@0: PKIX_DECREF(format); andre@0: PKIX_DECREF(issuerString); andre@0: PKIX_DECREF(subjectString); andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_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_CertPolicyMap_Hashcode( andre@0: PKIX_PL_Object *object, andre@0: PKIX_UInt32 *pHashcode, andre@0: void *plContext) andre@0: { andre@0: PKIX_UInt32 issuerHash = 0; andre@0: PKIX_UInt32 subjectHash = 0; andre@0: PKIX_PL_CertPolicyMap *certMap = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_Hashcode"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pHashcode); andre@0: andre@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTPOLICYMAP_TYPE, plContext), andre@0: PKIX_OBJECTNOTCERTPOLICYMAP); andre@0: andre@0: certMap = (PKIX_PL_CertPolicyMap *)object; andre@0: andre@0: PKIX_HASHCODE andre@0: (certMap->issuerDomainPolicy, andre@0: &issuerHash, andre@0: plContext, andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: PKIX_HASHCODE andre@0: (certMap->subjectDomainPolicy, andre@0: &subjectHash, andre@0: plContext, andre@0: PKIX_OBJECTHASHCODEFAILED); andre@0: andre@0: *pHashcode = issuerHash*31 + subjectHash; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_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_CertPolicyMap_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_CertPolicyMap *firstCertMap = NULL; andre@0: PKIX_PL_CertPolicyMap *secondCertMap = NULL; andre@0: PKIX_UInt32 secondType = 0; andre@0: PKIX_Boolean compare = PKIX_FALSE; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_Equals"); andre@0: PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); andre@0: andre@0: /* test that firstObject is a CertPolicyMap */ andre@0: PKIX_CHECK(pkix_CheckType andre@0: (firstObject, PKIX_CERTPOLICYMAP_TYPE, plContext), andre@0: PKIX_FIRSTOBJECTNOTCERTPOLICYMAP); andre@0: andre@0: /* andre@0: * Since we know firstObject is a CertPolicyMap, 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 CertPolicyMap, 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_CERTPOLICYMAP_TYPE) { andre@0: *pResult = PKIX_FALSE; andre@0: goto cleanup; andre@0: } andre@0: andre@0: firstCertMap = (PKIX_PL_CertPolicyMap *)firstObject; andre@0: secondCertMap = (PKIX_PL_CertPolicyMap *)secondObject; andre@0: andre@0: PKIX_EQUALS andre@0: (firstCertMap->issuerDomainPolicy, andre@0: secondCertMap->issuerDomainPolicy, andre@0: &compare, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: andre@0: if (compare) { andre@0: PKIX_EQUALS andre@0: (firstCertMap->subjectDomainPolicy, andre@0: secondCertMap->subjectDomainPolicy, andre@0: &compare, andre@0: plContext, andre@0: PKIX_OBJECTEQUALSFAILED); andre@0: } andre@0: andre@0: *pResult = compare; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_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_pl_CertPolicyMap_Duplicate( andre@0: PKIX_PL_Object *object, andre@0: PKIX_PL_Object **pNewObject, andre@0: void *plContext) andre@0: { andre@0: PKIX_PL_CertPolicyMap *original = NULL; andre@0: PKIX_PL_CertPolicyMap *copy = NULL; andre@0: andre@0: PKIX_ENTER(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_Duplicate"); andre@0: andre@0: PKIX_NULLCHECK_TWO(object, pNewObject); andre@0: andre@0: PKIX_CHECK(pkix_CheckType andre@0: (object, PKIX_CERTPOLICYMAP_TYPE, plContext), andre@0: PKIX_OBJECTARGUMENTNOTPOLICYMAP); andre@0: andre@0: original = (PKIX_PL_CertPolicyMap *)object; andre@0: andre@0: PKIX_CHECK(pkix_pl_CertPolicyMap_Create andre@0: (original->issuerDomainPolicy, andre@0: original->subjectDomainPolicy, andre@0: ©, andre@0: plContext), andre@0: PKIX_CERTPOLICYMAPCREATEFAILED); andre@0: andre@0: *pNewObject = (PKIX_PL_Object *)copy; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_CertPolicyMap_RegisterSelf andre@0: * DESCRIPTION: andre@0: * Registers PKIX_CERTPOLICYMAP_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_CertPolicyMap_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(CERTPOLICYMAP, "pkix_pl_CertPolicyMap_RegisterSelf"); andre@0: andre@0: entry.description = "CertPolicyMap"; andre@0: entry.objCounter = 0; andre@0: entry.typeObjectSize = sizeof(PKIX_PL_CertPolicyMap); andre@0: entry.destructor = pkix_pl_CertPolicyMap_Destroy; andre@0: entry.equalsFunction = pkix_pl_CertPolicyMap_Equals; andre@0: entry.hashcodeFunction = pkix_pl_CertPolicyMap_Hashcode; andre@0: entry.toStringFunction = pkix_pl_CertPolicyMap_ToString; andre@0: entry.comparator = NULL; andre@0: entry.duplicateFunction = pkix_pl_CertPolicyMap_Duplicate; andre@0: andre@0: systemClasses[PKIX_CERTPOLICYMAP_TYPE] = entry; andre@0: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* --Public-CertPolicyMap-Functions------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy andre@0: * (see comments in pkix_pl_pki.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy( andre@0: PKIX_PL_CertPolicyMap *policyMapping, andre@0: PKIX_PL_OID **pIssuerDomainPolicy, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER andre@0: (CERTPOLICYMAP, "PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy"); andre@0: andre@0: PKIX_NULLCHECK_TWO(policyMapping, pIssuerDomainPolicy); andre@0: andre@0: PKIX_INCREF(policyMapping->issuerDomainPolicy); andre@0: *pIssuerDomainPolicy = policyMapping->issuerDomainPolicy; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy andre@0: * (see comments in pkix_pl_pki.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy( andre@0: PKIX_PL_CertPolicyMap *policyMapping, andre@0: PKIX_PL_OID **pSubjectDomainPolicy, andre@0: void *plContext) andre@0: { andre@0: PKIX_ENTER andre@0: (CERTPOLICYMAP, "PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy"); andre@0: andre@0: PKIX_NULLCHECK_TWO(policyMapping, pSubjectDomainPolicy); andre@0: andre@0: PKIX_INCREF(policyMapping->subjectDomainPolicy); andre@0: *pSubjectDomainPolicy = policyMapping->subjectDomainPolicy; andre@0: andre@0: cleanup: andre@0: PKIX_RETURN(CERTPOLICYMAP); andre@0: }