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_certpolicyqualifier.c
40 * CertPolicyQualifier Type Functions
44 #include "pkix_pl_certpolicyqualifier.h"
47 * FUNCTION: pkix_pl_CertPolicyQualifier_Create
50 * Creates a CertPolicyQualifier object with the OID given by "oid"
51 * and the ByteArray given by "qualifier", and stores it at "pObject".
55 * Address of OID of the desired policyQualifierId; must be non-NULL
57 * Address of ByteArray with the desired value of the qualifier;
60 * Address where object 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 Fatal Error if the function fails in an unrecoverable way.
70 pkix_pl_CertPolicyQualifier_Create(
72 PKIX_PL_ByteArray
*qualifier
,
73 PKIX_PL_CertPolicyQualifier
**pObject
,
76 PKIX_PL_CertPolicyQualifier
*qual
= NULL
;
78 PKIX_ENTER(CERTPOLICYQUALIFIER
, "pkix_pl_CertPolicyQualifier_Create");
80 PKIX_NULLCHECK_THREE(oid
, qualifier
, pObject
);
82 PKIX_CHECK(PKIX_PL_Object_Alloc
83 (PKIX_CERTPOLICYQUALIFIER_TYPE
,
84 sizeof (PKIX_PL_CertPolicyQualifier
),
85 (PKIX_PL_Object
**)&qual
,
87 PKIX_COULDNOTCREATECERTPOLICYQUALIFIEROBJECT
);
90 qual
->policyQualifierId
= oid
;
92 PKIX_INCREF(qualifier
);
93 qual
->qualifier
= qualifier
;
101 PKIX_RETURN(CERTPOLICYQUALIFIER
);
105 * FUNCTION: pkix_pl_CertPolicyQualifier_Destroy
106 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
109 pkix_pl_CertPolicyQualifier_Destroy(
110 PKIX_PL_Object
*object
,
113 PKIX_PL_CertPolicyQualifier
*certPQ
= NULL
;
115 PKIX_ENTER(CERTPOLICYQUALIFIER
, "pkix_pl_CertPolicyQualifier_Destroy");
117 PKIX_NULLCHECK_ONE(object
);
119 PKIX_CHECK(pkix_CheckType
120 (object
, PKIX_CERTPOLICYQUALIFIER_TYPE
, plContext
),
121 PKIX_OBJECTNOTCERTPOLICYQUALIFIER
);
123 certPQ
= (PKIX_PL_CertPolicyQualifier
*)object
;
125 PKIX_DECREF(certPQ
->policyQualifierId
);
126 PKIX_DECREF(certPQ
->qualifier
);
130 PKIX_RETURN(CERTPOLICYQUALIFIER
);
134 * FUNCTION: pkix_pl_CertPolicyQualifier_ToString
135 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
138 pkix_pl_CertPolicyQualifier_ToString(
139 PKIX_PL_Object
*object
,
140 PKIX_PL_String
**pString
,
143 PKIX_PL_CertPolicyQualifier
*certPQ
= NULL
;
144 char *asciiFormat
= "%s:%s";
145 PKIX_PL_String
*formatString
= NULL
;
146 PKIX_PL_String
*pqIDString
= NULL
;
147 PKIX_PL_String
*pqValString
= NULL
;
148 PKIX_PL_String
*outString
= NULL
;
150 PKIX_ENTER(CERTPOLICYQUALIFIER
, "pkix_pl_CertPolicyQualifier_ToString");
152 PKIX_NULLCHECK_TWO(object
, pString
);
154 PKIX_CHECK(pkix_CheckType
155 (object
, PKIX_CERTPOLICYQUALIFIER_TYPE
, plContext
),
156 PKIX_OBJECTNOTCERTPOLICYQUALIFIER
);
158 certPQ
= (PKIX_PL_CertPolicyQualifier
*)object
;
161 * The policyQualifierId is required. If there is no qualifier,
162 * we should have a ByteArray of zero length.
164 PKIX_NULLCHECK_TWO(certPQ
->policyQualifierId
, certPQ
->qualifier
);
166 PKIX_CHECK(PKIX_PL_String_Create
167 (PKIX_ESCASCII
, asciiFormat
, 0, &formatString
, plContext
),
168 PKIX_STRINGCREATEFAILED
);
170 PKIX_TOSTRING(certPQ
->policyQualifierId
, &pqIDString
, plContext
,
171 PKIX_OIDTOSTRINGFAILED
);
173 PKIX_CHECK(pkix_pl_ByteArray_ToHexString
174 (certPQ
->qualifier
, &pqValString
, plContext
),
175 PKIX_BYTEARRAYTOHEXSTRINGFAILED
);
177 PKIX_CHECK(PKIX_PL_Sprintf
178 (&outString
, plContext
, formatString
, pqIDString
, pqValString
),
181 *pString
= outString
;
185 PKIX_DECREF(formatString
);
186 PKIX_DECREF(pqIDString
);
187 PKIX_DECREF(pqValString
);
188 PKIX_RETURN(CERTPOLICYQUALIFIER
);
192 * FUNCTION: pkix_pl_CertPolicyQualifier_Hashcode
193 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
196 pkix_pl_CertPolicyQualifier_Hashcode(
197 PKIX_PL_Object
*object
,
198 PKIX_UInt32
*pHashcode
,
201 PKIX_PL_CertPolicyQualifier
*certPQ
= NULL
;
202 PKIX_UInt32 cpidHash
= 0;
203 PKIX_UInt32 cpqHash
= 0;
205 PKIX_ENTER(CERTPOLICYQUALIFIER
, "pkix_pl_CertPolicyQualifier_Hashcode");
206 PKIX_NULLCHECK_TWO(object
, pHashcode
);
208 PKIX_CHECK(pkix_CheckType
209 (object
, PKIX_CERTPOLICYQUALIFIER_TYPE
, plContext
),
210 PKIX_OBJECTNOTCERTPOLICYQUALIFIER
);
212 certPQ
= (PKIX_PL_CertPolicyQualifier
*)object
;
214 PKIX_NULLCHECK_TWO(certPQ
->policyQualifierId
, certPQ
->qualifier
);
216 PKIX_HASHCODE(certPQ
->policyQualifierId
, &cpidHash
, plContext
,
217 PKIX_ERRORINOIDHASHCODE
);
219 PKIX_HASHCODE(certPQ
->qualifier
, &cpqHash
, plContext
,
220 PKIX_ERRORINBYTEARRAYHASHCODE
);
222 *pHashcode
= cpidHash
*31 + cpqHash
;
226 PKIX_RETURN(CERTPOLICYQUALIFIER
);
231 * FUNCTION: pkix_pl_CertPolicyQualifier_Equals
232 * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h)
235 pkix_pl_CertPolicyQualifier_Equals(
236 PKIX_PL_Object
*firstObject
,
237 PKIX_PL_Object
*secondObject
,
238 PKIX_Boolean
*pResult
,
241 PKIX_PL_CertPolicyQualifier
*firstCPQ
= NULL
;
242 PKIX_PL_CertPolicyQualifier
*secondCPQ
= NULL
;
243 PKIX_UInt32 secondType
= 0;
244 PKIX_Boolean compare
= PKIX_FALSE
;
246 PKIX_ENTER(CERTPOLICYQUALIFIER
, "pkix_pl_CertPolicyQualifier_Equals");
247 PKIX_NULLCHECK_THREE(firstObject
, secondObject
, pResult
);
249 /* test that firstObject is a CertPolicyQualifier */
250 PKIX_CHECK(pkix_CheckType
251 (firstObject
, PKIX_CERTPOLICYQUALIFIER_TYPE
, plContext
),
252 PKIX_FIRSTOBJECTNOTCERTPOLICYQUALIFIER
);
255 * Since we know firstObject is a CertPolicyQualifier,
256 * if both references are identical, they must be equal
258 if (firstObject
== secondObject
){
259 *pResult
= PKIX_TRUE
;
264 * If secondObject isn't a CertPolicyQualifier, 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_CERTPOLICYQUALIFIER_TYPE
) {
271 *pResult
= PKIX_FALSE
;
275 firstCPQ
= (PKIX_PL_CertPolicyQualifier
*)firstObject
;
276 secondCPQ
= (PKIX_PL_CertPolicyQualifier
*)secondObject
;
279 * Compare the value of the OID components
283 (firstCPQ
->policyQualifierId
, secondCPQ
->policyQualifierId
);
286 (firstCPQ
->policyQualifierId
,
287 secondCPQ
->policyQualifierId
,
290 PKIX_OIDEQUALSFAILED
);
293 * If the OIDs did not match, we don't need to
294 * compare the ByteArrays. If the OIDs did match,
295 * the return value is the value of the
296 * ByteArray comparison.
299 PKIX_NULLCHECK_TWO(firstCPQ
->qualifier
, secondCPQ
->qualifier
);
302 (firstCPQ
->qualifier
,
303 secondCPQ
->qualifier
,
306 PKIX_BYTEARRAYEQUALSFAILED
);
313 PKIX_RETURN(CERTPOLICYQUALIFIER
);
317 * FUNCTION: pkix_pl_CertPolicyQualifier_RegisterSelf
319 * Registers PKIX_CERTPOLICYQUALIFIER_TYPE and its related
320 * functions with systemClasses[]
322 * Not Thread Safe - for performance and complexity reasons
324 * Since this function is only called by PKIX_PL_Initialize,
325 * which should only be called once, it is acceptable that
326 * this function is not thread-safe.
329 pkix_pl_CertPolicyQualifier_RegisterSelf(void *plContext
)
332 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
333 pkix_ClassTable_Entry entry
;
335 PKIX_ENTER(CERTPOLICYQUALIFIER
,
336 "pkix_pl_CertPolicyQualifier_RegisterSelf");
338 entry
.description
= "CertPolicyQualifier";
339 entry
.objCounter
= 0;
340 entry
.typeObjectSize
= sizeof(PKIX_PL_CertPolicyQualifier
);
341 entry
.destructor
= pkix_pl_CertPolicyQualifier_Destroy
;
342 entry
.equalsFunction
= pkix_pl_CertPolicyQualifier_Equals
;
343 entry
.hashcodeFunction
= pkix_pl_CertPolicyQualifier_Hashcode
;
344 entry
.toStringFunction
= pkix_pl_CertPolicyQualifier_ToString
;
345 entry
.comparator
= NULL
;
346 entry
.duplicateFunction
= pkix_duplicateImmutable
;
348 systemClasses
[PKIX_CERTPOLICYQUALIFIER_TYPE
] = entry
;
350 PKIX_RETURN(CERTPOLICYQUALIFIER
);
353 /* --Public-CertPolicyQualifier-Functions------------------------- */
356 * FUNCTION: PKIX_PL_PolicyQualifier_GetPolicyQualifierId
357 * (see comments in pkix_pl_pki.h)
360 PKIX_PL_PolicyQualifier_GetPolicyQualifierId(
361 PKIX_PL_CertPolicyQualifier
*policyQualifierInfo
,
362 PKIX_PL_OID
**pPolicyQualifierId
,
365 PKIX_ENTER(CERTPOLICYQUALIFIER
,
366 "PKIX_PL_PolicyQualifier_GetPolicyQualifierId");
368 PKIX_NULLCHECK_TWO(policyQualifierInfo
, pPolicyQualifierId
);
370 PKIX_INCREF(policyQualifierInfo
->policyQualifierId
);
372 *pPolicyQualifierId
= policyQualifierInfo
->policyQualifierId
;
375 PKIX_RETURN(CERTPOLICYQUALIFIER
);
379 * FUNCTION: PKIX_PL_PolicyQualifier_GetQualifier
380 * (see comments in pkix_pl_pki.h)
383 PKIX_PL_PolicyQualifier_GetQualifier(
384 PKIX_PL_CertPolicyQualifier
*policyQualifierInfo
,
385 PKIX_PL_ByteArray
**pQualifier
,
388 PKIX_ENTER(CERTPOLICYQUALIFIER
, "PKIX_PL_PolicyQualifier_GetQualifier");
390 PKIX_NULLCHECK_TWO(policyQualifierInfo
, pQualifier
);
392 PKIX_INCREF(policyQualifierInfo
->qualifier
);
394 *pQualifier
= policyQualifierInfo
->qualifier
;
397 PKIX_RETURN(CERTPOLICYQUALIFIER
);