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_certpolicyinfo.c
40 * CertPolicyInfo Type Functions
44 #include "pkix_pl_certpolicyinfo.h"
47 * FUNCTION: pkix_pl_CertPolicyInfo_Create
50 * Creates a new CertPolicyInfo Object using the OID pointed to by "oid" and
51 * the List of CertPolicyQualifiers pointed to by "qualifiers", and stores it
52 * at "pObject". If a non-NULL list is provided, the caller is expected to
53 * have already set it to be immutable. The caller may provide an empty List,
54 * but a NULL List is preferable so a user does not need to call
55 * List_GetLength to get the number of qualifiers.
59 * OID of the desired PolicyInfo ID; must be non-NULL
61 * List of CertPolicyQualifiers; may be NULL or empty
63 * Address where object pointer will be stored. Must be non-NULL.
65 * Platform-specific context pointer.
67 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
69 * Returns NULL if the function succeeds.
70 * Returns a Fatal Error if the function fails in an unrecoverable way.
73 pkix_pl_CertPolicyInfo_Create(
75 PKIX_List
*qualifiers
,
76 PKIX_PL_CertPolicyInfo
**pObject
,
79 PKIX_PL_CertPolicyInfo
*policyInfo
= NULL
;
81 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_Create");
83 PKIX_NULLCHECK_TWO(oid
, pObject
);
85 PKIX_CHECK(PKIX_PL_Object_Alloc
86 (PKIX_CERTPOLICYINFO_TYPE
,
87 sizeof (PKIX_PL_CertPolicyInfo
),
88 (PKIX_PL_Object
**)&policyInfo
,
90 PKIX_COULDNOTCREATECERTPOLICYINFOOBJECT
);
93 policyInfo
->cpID
= oid
;
95 PKIX_INCREF(qualifiers
);
96 policyInfo
->policyQualifiers
= qualifiers
;
98 *pObject
= policyInfo
;
102 PKIX_DECREF(policyInfo
);
104 PKIX_RETURN(CERTPOLICYINFO
);
108 * FUNCTION: pkix_pl_CertPolicyInfo_Destroy
109 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
112 pkix_pl_CertPolicyInfo_Destroy(
113 PKIX_PL_Object
*object
,
116 PKIX_PL_CertPolicyInfo
*certPI
= NULL
;
118 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_Destroy");
120 PKIX_NULLCHECK_ONE(object
);
122 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYINFO_TYPE
, plContext
),
123 PKIX_OBJECTNOTCERTPOLICYINFO
);
125 certPI
= (PKIX_PL_CertPolicyInfo
*)object
;
127 PKIX_DECREF(certPI
->cpID
);
128 PKIX_DECREF(certPI
->policyQualifiers
);
132 PKIX_RETURN(CERTPOLICYINFO
);
136 * FUNCTION: pkix_pl_CertPolicyInfo_ToString
137 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
140 pkix_pl_CertPolicyInfo_ToString(
141 PKIX_PL_Object
*object
,
142 PKIX_PL_String
**pString
,
145 PKIX_PL_CertPolicyInfo
*certPI
= NULL
;
146 PKIX_PL_String
*oidString
= NULL
;
147 PKIX_PL_String
*listString
= NULL
;
148 PKIX_PL_String
*format
= NULL
;
149 PKIX_PL_String
*outString
= NULL
;
151 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_ToString");
153 PKIX_NULLCHECK_TWO(object
, pString
);
155 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYINFO_TYPE
, plContext
),
156 PKIX_OBJECTNOTCERTPOLICYINFO
);
158 certPI
= (PKIX_PL_CertPolicyInfo
*)object
;
160 PKIX_NULLCHECK_ONE(certPI
->cpID
);
166 PKIX_OIDTOSTRINGFAILED
);
169 (certPI
->policyQualifiers
,
172 PKIX_LISTTOSTRINGFAILED
);
174 /* Put them together in the form OID[Qualifiers] */
175 PKIX_CHECK(PKIX_PL_String_Create
176 (PKIX_ESCASCII
, "%s[%s]", 0, &format
, plContext
),
177 PKIX_ERRORINSTRINGCREATE
);
179 PKIX_CHECK(PKIX_PL_Sprintf
180 (&outString
, plContext
, format
, oidString
, listString
),
181 PKIX_ERRORINSPRINTF
);
183 *pString
= outString
;
187 PKIX_DECREF(oidString
);
188 PKIX_DECREF(listString
);
190 PKIX_RETURN(CERTPOLICYINFO
);
194 * FUNCTION: pkix_pl_CertPolicyInfo_Hashcode
195 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
198 pkix_pl_CertPolicyInfo_Hashcode(
199 PKIX_PL_Object
*object
,
200 PKIX_UInt32
*pHashcode
,
203 PKIX_PL_CertPolicyInfo
*certPI
= NULL
;
204 PKIX_UInt32 oidHash
= 0;
205 PKIX_UInt32 listHash
= 0;
207 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_Hashcode");
209 PKIX_NULLCHECK_TWO(object
, pHashcode
);
211 PKIX_CHECK(pkix_CheckType(object
, PKIX_CERTPOLICYINFO_TYPE
, plContext
),
212 PKIX_OBJECTNOTCERTPOLICYINFO
);
214 certPI
= (PKIX_PL_CertPolicyInfo
*)object
;
216 PKIX_NULLCHECK_ONE(certPI
->cpID
);
222 PKIX_ERRORINOIDHASHCODE
);
225 (certPI
->policyQualifiers
,
228 PKIX_ERRORINLISTHASHCODE
);
230 *pHashcode
= (31 * oidHash
) + listHash
;
234 PKIX_RETURN(CERTPOLICYINFO
);
239 * FUNCTION: pkix_pl_CertPolicyInfo_Equals
240 * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h)
243 pkix_pl_CertPolicyInfo_Equals(
244 PKIX_PL_Object
*firstObject
,
245 PKIX_PL_Object
*secondObject
,
246 PKIX_Boolean
*pResult
,
249 PKIX_PL_CertPolicyInfo
*firstCPI
= NULL
;
250 PKIX_PL_CertPolicyInfo
*secondCPI
= NULL
;
251 PKIX_UInt32 secondType
= 0;
252 PKIX_Boolean compare
= PKIX_FALSE
;
254 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_Equals");
255 PKIX_NULLCHECK_THREE(firstObject
, secondObject
, pResult
);
257 /* test that firstObject is a CertPolicyInfo */
258 PKIX_CHECK(pkix_CheckType
259 (firstObject
, PKIX_CERTPOLICYINFO_TYPE
, plContext
),
260 PKIX_FIRSTOBJECTNOTCERTPOLICYINFO
);
263 * Since we know firstObject is a CertPolicyInfo,
264 * if both references are identical, they must be equal
266 if (firstObject
== secondObject
){
267 *pResult
= PKIX_TRUE
;
272 * If secondObject isn't a CertPolicyInfo, we
273 * don't throw an error. We simply return FALSE.
275 PKIX_CHECK(PKIX_PL_Object_GetType
276 (secondObject
, &secondType
, plContext
),
277 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT
);
278 if (secondType
!= PKIX_CERTPOLICYINFO_TYPE
) {
279 *pResult
= PKIX_FALSE
;
283 firstCPI
= (PKIX_PL_CertPolicyInfo
*)firstObject
;
284 secondCPI
= (PKIX_PL_CertPolicyInfo
*)secondObject
;
287 * Compare the value of the OID components
290 PKIX_NULLCHECK_TWO(firstCPI
->cpID
, secondCPI
->cpID
);
297 PKIX_OIDEQUALSFAILED
);
300 * If the OIDs did not match, we don't need to
301 * compare the Lists. If the OIDs did match,
302 * the return value is the value of the
307 (firstCPI
->policyQualifiers
,
308 secondCPI
->policyQualifiers
,
311 PKIX_LISTEQUALSFAILED
);
318 PKIX_RETURN(CERTPOLICYINFO
);
322 * FUNCTION: pkix_pl_CertPolicyInfo_RegisterSelf
324 * Registers PKIX_CERTPOLICYINFO_TYPE and its related
325 * functions with systemClasses[]
327 * Not Thread Safe - for performance and complexity reasons
329 * Since this function is only called by PKIX_PL_Initialize,
330 * which should only be called once, it is acceptable that
331 * this function is not thread-safe.
334 pkix_pl_CertPolicyInfo_RegisterSelf(void *plContext
)
336 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
337 pkix_ClassTable_Entry entry
;
339 PKIX_ENTER(CERTPOLICYINFO
, "pkix_pl_CertPolicyInfo_RegisterSelf");
341 entry
.description
= "CertPolicyInfo";
342 entry
.objCounter
= 0;
343 entry
.typeObjectSize
= sizeof(PKIX_PL_CertPolicyInfo
);
344 entry
.destructor
= pkix_pl_CertPolicyInfo_Destroy
;
345 entry
.equalsFunction
= pkix_pl_CertPolicyInfo_Equals
;
346 entry
.hashcodeFunction
= pkix_pl_CertPolicyInfo_Hashcode
;
347 entry
.toStringFunction
= pkix_pl_CertPolicyInfo_ToString
;
348 entry
.comparator
= NULL
;
349 entry
.duplicateFunction
= pkix_duplicateImmutable
;
351 systemClasses
[PKIX_CERTPOLICYINFO_TYPE
] = entry
;
353 PKIX_RETURN(CERTPOLICYINFO
);
356 /* --Public-CertPolicyInfo-Functions------------------------- */
359 * FUNCTION: PKIX_PL_CertPolicyInfo_GetPolicyId
360 * (see comments in pkix_pl_pki.h)
363 PKIX_PL_CertPolicyInfo_GetPolicyId(
364 PKIX_PL_CertPolicyInfo
*policyInfo
,
365 PKIX_PL_OID
**pPolicyId
,
368 PKIX_ENTER(CERTPOLICYINFO
, "PKIX_PL_CertPolicyInfo_GetPolicyId");
370 PKIX_NULLCHECK_TWO(policyInfo
, pPolicyId
);
372 PKIX_INCREF(policyInfo
->cpID
);
374 *pPolicyId
= policyInfo
->cpID
;
377 PKIX_RETURN(CERTPOLICYINFO
);
381 * FUNCTION: PKIX_PL_CertPolicyInfo_GetPolQualifiers
382 * (see comments in pkix_pl_pki.h)
385 PKIX_PL_CertPolicyInfo_GetPolQualifiers(
386 PKIX_PL_CertPolicyInfo
*policyInfo
,
390 PKIX_ENTER(CERTPOLICYINFO
, "PKIX_PL_CertPolicyInfo_GetPolQualifiers");
392 PKIX_NULLCHECK_TWO(policyInfo
, pQuals
);
394 PKIX_INCREF(policyInfo
->policyQualifiers
);
397 * This List is created in PKIX_PL_Cert_DecodePolicyInfo
398 * and is set immutable immediately after being created.
400 *pQuals
= policyInfo
->policyQualifiers
;
403 PKIX_RETURN(CERTPOLICYINFO
);