1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the PKIX-C library.
16 * The Initial Developer of the Original Code is
17 * Sun Microsystems, Inc.
18 * Portions created by the Initial Developer are
19 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
22 * Sun Microsystems, Inc.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * pkix_pl_certpolicymap.c
40 * CertPolicyMap Type Functions
44 #include "pkix_pl_certpolicymap.h"
47 * FUNCTION: pkix_pl_CertPolicyMap_Create
50 * Creates a new CertPolicyMap Object pairing the OID given by
51 * "issuerDomainPolicy" with the OID given by "subjectDomainPolicy", and
52 * stores the result at "pCertPolicyMap".
55 * "issuerDomainPolicy"
56 * Address of the OID of the IssuerDomainPolicy. Must be non-NULL.
57 * "subjectDomainPolicy"
58 * Address of the OID of the SubjectDomainPolicy. Must be non-NULL.
60 * Address where CertPolicyMap pointer will be stored. Must be non-NULL.
62 * Platform-specific context pointer.
64 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
66 * Returns NULL if the function succeeds.
67 * Returns a CertPolicyMap Error if the function fails in a non-fatal way.
68 * Returns a Fatal Error if the function fails in an unrecoverable way.
71 pkix_pl_CertPolicyMap_Create(
72 PKIX_PL_OID
*issuerDomainPolicy
,
73 PKIX_PL_OID
*subjectDomainPolicy
,
74 PKIX_PL_CertPolicyMap
**pCertPolicyMap
,
77 PKIX_PL_CertPolicyMap
*policyMap
= NULL
;
79 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_Create");
82 (issuerDomainPolicy
, subjectDomainPolicy
, pCertPolicyMap
);
84 PKIX_CHECK(PKIX_PL_Object_Alloc
85 (PKIX_CERTPOLICYMAP_TYPE
,
86 sizeof (PKIX_PL_CertPolicyMap
),
87 (PKIX_PL_Object
**)&policyMap
,
89 PKIX_COULDNOTCREATECERTPOLICYMAPOBJECT
);
91 PKIX_INCREF(issuerDomainPolicy
);
92 policyMap
->issuerDomainPolicy
= issuerDomainPolicy
;
94 PKIX_INCREF(subjectDomainPolicy
);
95 policyMap
->subjectDomainPolicy
= subjectDomainPolicy
;
97 *pCertPolicyMap
= policyMap
;
101 PKIX_RETURN(CERTPOLICYMAP
);
105 * FUNCTION: pkix_pl_CertPolicyMap_Destroy
106 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
109 pkix_pl_CertPolicyMap_Destroy(
110 PKIX_PL_Object
*object
,
113 PKIX_PL_CertPolicyMap
*certMap
= NULL
;
115 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_Destroy");
117 PKIX_NULLCHECK_ONE(object
);
119 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYMAP_TYPE
, plContext
),
120 PKIX_OBJECTNOTCERTPOLICYMAP
);
122 certMap
= (PKIX_PL_CertPolicyMap
*)object
;
124 PKIX_DECREF(certMap
->issuerDomainPolicy
);
125 PKIX_DECREF(certMap
->subjectDomainPolicy
);
129 PKIX_RETURN(CERTPOLICYMAP
);
133 * FUNCTION: pkix_pl_CertPolicyMap_ToString
134 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
137 pkix_pl_CertPolicyMap_ToString(
138 PKIX_PL_Object
*object
,
139 PKIX_PL_String
**pString
,
142 PKIX_PL_CertPolicyMap
*certMap
= NULL
;
143 PKIX_PL_String
*format
= NULL
;
144 PKIX_PL_String
*outString
= NULL
;
145 PKIX_PL_String
*issuerString
= NULL
;
146 PKIX_PL_String
*subjectString
= NULL
;
148 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_ToString");
150 PKIX_NULLCHECK_TWO(object
, pString
);
152 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYMAP_TYPE
, plContext
),
153 PKIX_OBJECTNOTCERTPOLICYMAP
);
155 certMap
= (PKIX_PL_CertPolicyMap
*)object
;
158 (certMap
->issuerDomainPolicy
,
161 PKIX_OBJECTTOSTRINGFAILED
);
164 (certMap
->subjectDomainPolicy
,
167 PKIX_OBJECTTOSTRINGFAILED
);
169 /* Put them together in the form issuerPolicy=>subjectPolicy */
170 PKIX_CHECK(PKIX_PL_String_Create
171 (PKIX_ESCASCII
, "%s=>%s", 0, &format
, plContext
),
172 PKIX_ERRORINSTRINGCREATE
);
174 PKIX_CHECK(PKIX_PL_Sprintf
175 (&outString
, plContext
, format
, issuerString
, subjectString
),
176 PKIX_ERRORINSPRINTF
);
178 *pString
= outString
;
182 PKIX_DECREF(issuerString
);
183 PKIX_DECREF(subjectString
);
185 PKIX_RETURN(CERTPOLICYMAP
);
189 * FUNCTION: pkix_pl_CertPolicyMap_Hashcode
190 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
193 pkix_pl_CertPolicyMap_Hashcode(
194 PKIX_PL_Object
*object
,
195 PKIX_UInt32
*pHashcode
,
198 PKIX_UInt32 issuerHash
= 0;
199 PKIX_UInt32 subjectHash
= 0;
200 PKIX_PL_CertPolicyMap
*certMap
= NULL
;
202 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_Hashcode");
204 PKIX_NULLCHECK_TWO(object
, pHashcode
);
206 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYMAP_TYPE
, plContext
),
207 PKIX_OBJECTNOTCERTPOLICYMAP
);
209 certMap
= (PKIX_PL_CertPolicyMap
*)object
;
212 (certMap
->issuerDomainPolicy
,
215 PKIX_OBJECTHASHCODEFAILED
);
218 (certMap
->subjectDomainPolicy
,
221 PKIX_OBJECTHASHCODEFAILED
);
223 *pHashcode
= issuerHash
*31 + subjectHash
;
227 PKIX_RETURN(CERTPOLICYMAP
);
231 * FUNCTION: pkix_pl_CertPolicyMap_Equals
232 * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h)
235 pkix_pl_CertPolicyMap_Equals(
236 PKIX_PL_Object
*firstObject
,
237 PKIX_PL_Object
*secondObject
,
238 PKIX_Boolean
*pResult
,
241 PKIX_PL_CertPolicyMap
*firstCertMap
= NULL
;
242 PKIX_PL_CertPolicyMap
*secondCertMap
= NULL
;
243 PKIX_UInt32 secondType
= 0;
244 PKIX_Boolean compare
= PKIX_FALSE
;
246 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_Equals");
247 PKIX_NULLCHECK_THREE(firstObject
, secondObject
, pResult
);
249 /* test that firstObject is a CertPolicyMap */
250 PKIX_CHECK(pkix_CheckType
251 (firstObject
, PKIX_CERTPOLICYMAP_TYPE
, plContext
),
252 PKIX_FIRSTOBJECTNOTCERTPOLICYMAP
);
255 * Since we know firstObject is a CertPolicyMap,
256 * if both references are identical, they must be equal
258 if (firstObject
== secondObject
){
259 *pResult
= PKIX_TRUE
;
264 * If secondObject isn't a CertPolicyMap, we
265 * don't throw an error. We simply return FALSE.
267 PKIX_CHECK(PKIX_PL_Object_GetType
268 (secondObject
, &secondType
, plContext
),
269 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT
);
270 if (secondType
!= PKIX_CERTPOLICYMAP_TYPE
) {
271 *pResult
= PKIX_FALSE
;
275 firstCertMap
= (PKIX_PL_CertPolicyMap
*)firstObject
;
276 secondCertMap
= (PKIX_PL_CertPolicyMap
*)secondObject
;
279 (firstCertMap
->issuerDomainPolicy
,
280 secondCertMap
->issuerDomainPolicy
,
283 PKIX_OBJECTEQUALSFAILED
);
287 (firstCertMap
->subjectDomainPolicy
,
288 secondCertMap
->subjectDomainPolicy
,
291 PKIX_OBJECTEQUALSFAILED
);
298 PKIX_RETURN(CERTPOLICYMAP
);
302 * FUNCTION: pkix_pl_CertPolicyMap_Duplicate
303 * (see comments for PKIX_PL_Duplicate_Callback in pkix_pl_system.h)
306 pkix_pl_CertPolicyMap_Duplicate(
307 PKIX_PL_Object
*object
,
308 PKIX_PL_Object
**pNewObject
,
311 PKIX_PL_CertPolicyMap
*original
= NULL
;
312 PKIX_PL_CertPolicyMap
*copy
= NULL
;
314 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_Duplicate");
316 PKIX_NULLCHECK_TWO(object
, pNewObject
);
318 PKIX_CHECK(pkix_CheckType
319 (object
, PKIX_CERTPOLICYMAP_TYPE
, plContext
),
320 PKIX_OBJECTARGUMENTNOTPOLICYMAP
);
322 original
= (PKIX_PL_CertPolicyMap
*)object
;
324 PKIX_CHECK(pkix_pl_CertPolicyMap_Create
325 (original
->issuerDomainPolicy
,
326 original
->subjectDomainPolicy
,
329 PKIX_CERTPOLICYMAPCREATEFAILED
);
331 *pNewObject
= (PKIX_PL_Object
*)copy
;
335 PKIX_RETURN(CERTPOLICYMAP
);
339 * FUNCTION: pkix_pl_CertPolicyMap_RegisterSelf
341 * Registers PKIX_CERTPOLICYMAP_TYPE and its related
342 * functions with systemClasses[]
344 * Not Thread Safe - for performance and complexity reasons
346 * Since this function is only called by PKIX_PL_Initialize,
347 * which should only be called once, it is acceptable that
348 * this function is not thread-safe.
351 pkix_pl_CertPolicyMap_RegisterSelf(void *plContext
)
353 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
354 pkix_ClassTable_Entry entry
;
356 PKIX_ENTER(CERTPOLICYMAP
, "pkix_pl_CertPolicyMap_RegisterSelf");
358 entry
.description
= "CertPolicyMap";
359 entry
.objCounter
= 0;
360 entry
.typeObjectSize
= sizeof(PKIX_PL_CertPolicyMap
);
361 entry
.destructor
= pkix_pl_CertPolicyMap_Destroy
;
362 entry
.equalsFunction
= pkix_pl_CertPolicyMap_Equals
;
363 entry
.hashcodeFunction
= pkix_pl_CertPolicyMap_Hashcode
;
364 entry
.toStringFunction
= pkix_pl_CertPolicyMap_ToString
;
365 entry
.comparator
= NULL
;
366 entry
.duplicateFunction
= pkix_pl_CertPolicyMap_Duplicate
;
368 systemClasses
[PKIX_CERTPOLICYMAP_TYPE
] = entry
;
370 PKIX_RETURN(CERTPOLICYMAP
);
373 /* --Public-CertPolicyMap-Functions------------------------- */
376 * FUNCTION: PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy
377 * (see comments in pkix_pl_pki.h)
380 PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy(
381 PKIX_PL_CertPolicyMap
*policyMapping
,
382 PKIX_PL_OID
**pIssuerDomainPolicy
,
386 (CERTPOLICYMAP
, "PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy");
388 PKIX_NULLCHECK_TWO(policyMapping
, pIssuerDomainPolicy
);
390 PKIX_INCREF(policyMapping
->issuerDomainPolicy
);
391 *pIssuerDomainPolicy
= policyMapping
->issuerDomainPolicy
;
394 PKIX_RETURN(CERTPOLICYMAP
);
398 * FUNCTION: PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy
399 * (see comments in pkix_pl_pki.h)
402 PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy(
403 PKIX_PL_CertPolicyMap
*policyMapping
,
404 PKIX_PL_OID
**pSubjectDomainPolicy
,
408 (CERTPOLICYMAP
, "PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy");
410 PKIX_NULLCHECK_TWO(policyMapping
, pSubjectDomainPolicy
);
412 PKIX_INCREF(policyMapping
->subjectDomainPolicy
);
413 *pSubjectDomainPolicy
= policyMapping
->subjectDomainPolicy
;
416 PKIX_RETURN(CERTPOLICYMAP
);