Mercurial > trustbridge > nss-cmake-static
comparison nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_certpolicyqualifier.c @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
4 /* | |
5 * pkix_pl_certpolicyqualifier.c | |
6 * | |
7 * CertPolicyQualifier Type Functions | |
8 * | |
9 */ | |
10 | |
11 #include "pkix_pl_certpolicyqualifier.h" | |
12 | |
13 /* | |
14 * FUNCTION: pkix_pl_CertPolicyQualifier_Create | |
15 * DESCRIPTION: | |
16 * | |
17 * Creates a CertPolicyQualifier object with the OID given by "oid" | |
18 * and the ByteArray given by "qualifier", and stores it at "pObject". | |
19 * | |
20 * PARAMETERS | |
21 * "oid" | |
22 * Address of OID of the desired policyQualifierId; must be non-NULL | |
23 * "qualifier" | |
24 * Address of ByteArray with the desired value of the qualifier; | |
25 * must be non-NULL | |
26 * "pObject" | |
27 * Address where object pointer will be stored. Must be non-NULL. | |
28 * "plContext" | |
29 * Platform-specific context pointer. | |
30 * THREAD SAFETY: | |
31 * Thread Safe (see Thread Safety Definitions in Programmer's Guide) | |
32 * RETURNS: | |
33 * Returns NULL if the function succeeds. | |
34 * Returns a Fatal Error if the function fails in an unrecoverable way. | |
35 */ | |
36 PKIX_Error * | |
37 pkix_pl_CertPolicyQualifier_Create( | |
38 PKIX_PL_OID *oid, | |
39 PKIX_PL_ByteArray *qualifier, | |
40 PKIX_PL_CertPolicyQualifier **pObject, | |
41 void *plContext) | |
42 { | |
43 PKIX_PL_CertPolicyQualifier *qual = NULL; | |
44 | |
45 PKIX_ENTER(CERTPOLICYQUALIFIER, "pkix_pl_CertPolicyQualifier_Create"); | |
46 | |
47 PKIX_NULLCHECK_THREE(oid, qualifier, pObject); | |
48 | |
49 PKIX_CHECK(PKIX_PL_Object_Alloc | |
50 (PKIX_CERTPOLICYQUALIFIER_TYPE, | |
51 sizeof (PKIX_PL_CertPolicyQualifier), | |
52 (PKIX_PL_Object **)&qual, | |
53 plContext), | |
54 PKIX_COULDNOTCREATECERTPOLICYQUALIFIEROBJECT); | |
55 | |
56 PKIX_INCREF(oid); | |
57 qual->policyQualifierId = oid; | |
58 | |
59 PKIX_INCREF(qualifier); | |
60 qual->qualifier = qualifier; | |
61 | |
62 *pObject = qual; | |
63 qual = NULL; | |
64 | |
65 cleanup: | |
66 PKIX_DECREF(qual); | |
67 | |
68 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
69 } | |
70 | |
71 /* | |
72 * FUNCTION: pkix_pl_CertPolicyQualifier_Destroy | |
73 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) | |
74 */ | |
75 static PKIX_Error * | |
76 pkix_pl_CertPolicyQualifier_Destroy( | |
77 PKIX_PL_Object *object, | |
78 void *plContext) | |
79 { | |
80 PKIX_PL_CertPolicyQualifier *certPQ = NULL; | |
81 | |
82 PKIX_ENTER(CERTPOLICYQUALIFIER, "pkix_pl_CertPolicyQualifier_Destroy"); | |
83 | |
84 PKIX_NULLCHECK_ONE(object); | |
85 | |
86 PKIX_CHECK(pkix_CheckType | |
87 (object, PKIX_CERTPOLICYQUALIFIER_TYPE, plContext), | |
88 PKIX_OBJECTNOTCERTPOLICYQUALIFIER); | |
89 | |
90 certPQ = (PKIX_PL_CertPolicyQualifier*)object; | |
91 | |
92 PKIX_DECREF(certPQ->policyQualifierId); | |
93 PKIX_DECREF(certPQ->qualifier); | |
94 | |
95 cleanup: | |
96 | |
97 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
98 } | |
99 | |
100 /* | |
101 * FUNCTION: pkix_pl_CertPolicyQualifier_ToString | |
102 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h) | |
103 */ | |
104 static PKIX_Error * | |
105 pkix_pl_CertPolicyQualifier_ToString( | |
106 PKIX_PL_Object *object, | |
107 PKIX_PL_String **pString, | |
108 void *plContext) | |
109 { | |
110 PKIX_PL_CertPolicyQualifier *certPQ = NULL; | |
111 char *asciiFormat = "%s:%s"; | |
112 PKIX_PL_String *formatString = NULL; | |
113 PKIX_PL_String *pqIDString = NULL; | |
114 PKIX_PL_String *pqValString = NULL; | |
115 PKIX_PL_String *outString = NULL; | |
116 | |
117 PKIX_ENTER(CERTPOLICYQUALIFIER, "pkix_pl_CertPolicyQualifier_ToString"); | |
118 | |
119 PKIX_NULLCHECK_TWO(object, pString); | |
120 | |
121 PKIX_CHECK(pkix_CheckType | |
122 (object, PKIX_CERTPOLICYQUALIFIER_TYPE, plContext), | |
123 PKIX_OBJECTNOTCERTPOLICYQUALIFIER); | |
124 | |
125 certPQ = (PKIX_PL_CertPolicyQualifier *)object; | |
126 | |
127 /* | |
128 * The policyQualifierId is required. If there is no qualifier, | |
129 * we should have a ByteArray of zero length. | |
130 */ | |
131 PKIX_NULLCHECK_TWO(certPQ->policyQualifierId, certPQ->qualifier); | |
132 | |
133 PKIX_CHECK(PKIX_PL_String_Create | |
134 (PKIX_ESCASCII, asciiFormat, 0, &formatString, plContext), | |
135 PKIX_STRINGCREATEFAILED); | |
136 | |
137 PKIX_TOSTRING(certPQ->policyQualifierId, &pqIDString, plContext, | |
138 PKIX_OIDTOSTRINGFAILED); | |
139 | |
140 PKIX_CHECK(pkix_pl_ByteArray_ToHexString | |
141 (certPQ->qualifier, &pqValString, plContext), | |
142 PKIX_BYTEARRAYTOHEXSTRINGFAILED); | |
143 | |
144 PKIX_CHECK(PKIX_PL_Sprintf | |
145 (&outString, plContext, formatString, pqIDString, pqValString), | |
146 PKIX_SPRINTFFAILED); | |
147 | |
148 *pString = outString; | |
149 | |
150 cleanup: | |
151 | |
152 PKIX_DECREF(formatString); | |
153 PKIX_DECREF(pqIDString); | |
154 PKIX_DECREF(pqValString); | |
155 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
156 } | |
157 | |
158 /* | |
159 * FUNCTION: pkix_pl_CertPolicyQualifier_Hashcode | |
160 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) | |
161 */ | |
162 static PKIX_Error * | |
163 pkix_pl_CertPolicyQualifier_Hashcode( | |
164 PKIX_PL_Object *object, | |
165 PKIX_UInt32 *pHashcode, | |
166 void *plContext) | |
167 { | |
168 PKIX_PL_CertPolicyQualifier *certPQ = NULL; | |
169 PKIX_UInt32 cpidHash = 0; | |
170 PKIX_UInt32 cpqHash = 0; | |
171 | |
172 PKIX_ENTER(CERTPOLICYQUALIFIER, "pkix_pl_CertPolicyQualifier_Hashcode"); | |
173 PKIX_NULLCHECK_TWO(object, pHashcode); | |
174 | |
175 PKIX_CHECK(pkix_CheckType | |
176 (object, PKIX_CERTPOLICYQUALIFIER_TYPE, plContext), | |
177 PKIX_OBJECTNOTCERTPOLICYQUALIFIER); | |
178 | |
179 certPQ = (PKIX_PL_CertPolicyQualifier *)object; | |
180 | |
181 PKIX_NULLCHECK_TWO(certPQ->policyQualifierId, certPQ->qualifier); | |
182 | |
183 PKIX_HASHCODE(certPQ->policyQualifierId, &cpidHash, plContext, | |
184 PKIX_ERRORINOIDHASHCODE); | |
185 | |
186 PKIX_HASHCODE(certPQ->qualifier, &cpqHash, plContext, | |
187 PKIX_ERRORINBYTEARRAYHASHCODE); | |
188 | |
189 *pHashcode = cpidHash*31 + cpqHash; | |
190 | |
191 cleanup: | |
192 | |
193 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
194 } | |
195 | |
196 | |
197 /* | |
198 * FUNCTION: pkix_pl_CertPolicyQualifier_Equals | |
199 * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h) | |
200 */ | |
201 static PKIX_Error * | |
202 pkix_pl_CertPolicyQualifier_Equals( | |
203 PKIX_PL_Object *firstObject, | |
204 PKIX_PL_Object *secondObject, | |
205 PKIX_Boolean *pResult, | |
206 void *plContext) | |
207 { | |
208 PKIX_PL_CertPolicyQualifier *firstCPQ = NULL; | |
209 PKIX_PL_CertPolicyQualifier *secondCPQ = NULL; | |
210 PKIX_UInt32 secondType = 0; | |
211 PKIX_Boolean compare = PKIX_FALSE; | |
212 | |
213 PKIX_ENTER(CERTPOLICYQUALIFIER, "pkix_pl_CertPolicyQualifier_Equals"); | |
214 PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); | |
215 | |
216 /* test that firstObject is a CertPolicyQualifier */ | |
217 PKIX_CHECK(pkix_CheckType | |
218 (firstObject, PKIX_CERTPOLICYQUALIFIER_TYPE, plContext), | |
219 PKIX_FIRSTOBJECTNOTCERTPOLICYQUALIFIER); | |
220 | |
221 /* | |
222 * Since we know firstObject is a CertPolicyQualifier, | |
223 * if both references are identical, they must be equal | |
224 */ | |
225 if (firstObject == secondObject){ | |
226 *pResult = PKIX_TRUE; | |
227 goto cleanup; | |
228 } | |
229 | |
230 /* | |
231 * If secondObject isn't a CertPolicyQualifier, we | |
232 * don't throw an error. We simply return FALSE. | |
233 */ | |
234 PKIX_CHECK(PKIX_PL_Object_GetType | |
235 (secondObject, &secondType, plContext), | |
236 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT); | |
237 if (secondType != PKIX_CERTPOLICYQUALIFIER_TYPE) { | |
238 *pResult = PKIX_FALSE; | |
239 goto cleanup; | |
240 } | |
241 | |
242 firstCPQ = (PKIX_PL_CertPolicyQualifier *)firstObject; | |
243 secondCPQ = (PKIX_PL_CertPolicyQualifier *)secondObject; | |
244 | |
245 /* | |
246 * Compare the value of the OID components | |
247 */ | |
248 | |
249 PKIX_NULLCHECK_TWO | |
250 (firstCPQ->policyQualifierId, secondCPQ->policyQualifierId); | |
251 | |
252 PKIX_EQUALS | |
253 (firstCPQ->policyQualifierId, | |
254 secondCPQ->policyQualifierId, | |
255 &compare, | |
256 plContext, | |
257 PKIX_OIDEQUALSFAILED); | |
258 | |
259 /* | |
260 * If the OIDs did not match, we don't need to | |
261 * compare the ByteArrays. If the OIDs did match, | |
262 * the return value is the value of the | |
263 * ByteArray comparison. | |
264 */ | |
265 if (compare) { | |
266 PKIX_NULLCHECK_TWO(firstCPQ->qualifier, secondCPQ->qualifier); | |
267 | |
268 PKIX_EQUALS | |
269 (firstCPQ->qualifier, | |
270 secondCPQ->qualifier, | |
271 &compare, | |
272 plContext, | |
273 PKIX_BYTEARRAYEQUALSFAILED); | |
274 } | |
275 | |
276 *pResult = compare; | |
277 | |
278 cleanup: | |
279 | |
280 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
281 } | |
282 | |
283 /* | |
284 * FUNCTION: pkix_pl_CertPolicyQualifier_RegisterSelf | |
285 * DESCRIPTION: | |
286 * Registers PKIX_CERTPOLICYQUALIFIER_TYPE and its related | |
287 * functions with systemClasses[] | |
288 * THREAD SAFETY: | |
289 * Not Thread Safe - for performance and complexity reasons | |
290 * | |
291 * Since this function is only called by PKIX_PL_Initialize, | |
292 * which should only be called once, it is acceptable that | |
293 * this function is not thread-safe. | |
294 */ | |
295 PKIX_Error * | |
296 pkix_pl_CertPolicyQualifier_RegisterSelf(void *plContext) | |
297 { | |
298 | |
299 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; | |
300 pkix_ClassTable_Entry entry; | |
301 | |
302 PKIX_ENTER(CERTPOLICYQUALIFIER, | |
303 "pkix_pl_CertPolicyQualifier_RegisterSelf"); | |
304 | |
305 entry.description = "CertPolicyQualifier"; | |
306 entry.objCounter = 0; | |
307 entry.typeObjectSize = sizeof(PKIX_PL_CertPolicyQualifier); | |
308 entry.destructor = pkix_pl_CertPolicyQualifier_Destroy; | |
309 entry.equalsFunction = pkix_pl_CertPolicyQualifier_Equals; | |
310 entry.hashcodeFunction = pkix_pl_CertPolicyQualifier_Hashcode; | |
311 entry.toStringFunction = pkix_pl_CertPolicyQualifier_ToString; | |
312 entry.comparator = NULL; | |
313 entry.duplicateFunction = pkix_duplicateImmutable; | |
314 | |
315 systemClasses[PKIX_CERTPOLICYQUALIFIER_TYPE] = entry; | |
316 | |
317 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
318 } | |
319 | |
320 /* --Public-CertPolicyQualifier-Functions------------------------- */ | |
321 | |
322 /* | |
323 * FUNCTION: PKIX_PL_PolicyQualifier_GetPolicyQualifierId | |
324 * (see comments in pkix_pl_pki.h) | |
325 */ | |
326 PKIX_Error * | |
327 PKIX_PL_PolicyQualifier_GetPolicyQualifierId( | |
328 PKIX_PL_CertPolicyQualifier *policyQualifierInfo, | |
329 PKIX_PL_OID **pPolicyQualifierId, | |
330 void *plContext) | |
331 { | |
332 PKIX_ENTER(CERTPOLICYQUALIFIER, | |
333 "PKIX_PL_PolicyQualifier_GetPolicyQualifierId"); | |
334 | |
335 PKIX_NULLCHECK_TWO(policyQualifierInfo, pPolicyQualifierId); | |
336 | |
337 PKIX_INCREF(policyQualifierInfo->policyQualifierId); | |
338 | |
339 *pPolicyQualifierId = policyQualifierInfo->policyQualifierId; | |
340 | |
341 cleanup: | |
342 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
343 } | |
344 | |
345 /* | |
346 * FUNCTION: PKIX_PL_PolicyQualifier_GetQualifier | |
347 * (see comments in pkix_pl_pki.h) | |
348 */ | |
349 PKIX_Error * | |
350 PKIX_PL_PolicyQualifier_GetQualifier( | |
351 PKIX_PL_CertPolicyQualifier *policyQualifierInfo, | |
352 PKIX_PL_ByteArray **pQualifier, | |
353 void *plContext) | |
354 { | |
355 PKIX_ENTER(CERTPOLICYQUALIFIER, "PKIX_PL_PolicyQualifier_GetQualifier"); | |
356 | |
357 PKIX_NULLCHECK_TWO(policyQualifierInfo, pQualifier); | |
358 | |
359 PKIX_INCREF(policyQualifierInfo->qualifier); | |
360 | |
361 *pQualifier = policyQualifierInfo->qualifier; | |
362 | |
363 cleanup: | |
364 PKIX_RETURN(CERTPOLICYQUALIFIER); | |
365 } |