Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / libpkix / pkix_pl_nss / pki / pkix_pl_x500name.c
blob15cdd361b1081ce5cd40e818a0adfeeab49340ee
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
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Sun Microsystems
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_x500name.c
40 * X500Name Object Functions
44 #include "pkix_pl_x500name.h"
46 /* --Private-X500Name-Functions------------------------------------- */
49 * FUNCTION: pkix_pl_X500Name_CompareDERBytes
50 * DESCRIPTION:
52 * Checks whether the DER encoding of the X500Name pointed to by
53 * "firstX500Name" is byte-for-byte equal with the DER encoding of the
54 * X500Name pointed to by "secondX500Name" and stores the Boolean result at
55 * "pResult".
57 * PARAMETERS
58 * "firstX500Name"
59 * Address of first X500Name. Must be non-NULL.
60 * "secondX500Name"
61 * Address of second X500Name. Must be non-NULL.
62 * "pResult"
63 * Address where Boolean will be stored. Must be non-NULL.
64 * "plContext"
65 * Platform-specific context pointer.
66 * THREAD SAFETY:
67 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
68 * RETURNS:
69 * Returns NULL if the function succeeds.
70 * Returns a X500Name Error if the function fails in a non-fatal way.
71 * Returns a Fatal Error if the function fails in an unrecoverable way.
73 static PKIX_Error *
74 pkix_pl_X500Name_CompareDERBytes(
75 PKIX_PL_X500Name *firstX500Name,
76 PKIX_PL_X500Name *secondX500Name,
77 PKIX_Boolean *pResult,
78 void *plContext)
80 CERTName *firstName = NULL;
81 CERTName *secondName = NULL;
82 CERTRDN **ardns = NULL;
83 CERTRDN **brdns = NULL;
84 CERTRDN *ardn = NULL;
85 CERTRDN *brdn = NULL;
86 CERTAVA **aavas = NULL;
87 CERTAVA **bavas = NULL;
88 CERTAVA *aava = NULL;
89 CERTAVA *bava = NULL;
90 PKIX_UInt32 ac, bc;
91 SECComparison rv;
93 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_CompareDERBytes");
94 PKIX_NULLCHECK_THREE(firstX500Name, secondX500Name, pResult);
96 firstName = firstX500Name->nssDN;
97 secondName = secondX500Name->nssDN;
99 PKIX_NULLCHECK_TWO(firstName, secondName);
101 ardns = firstName->rdns;
102 brdns = secondName->rdns;
104 /* if array of rdn's not same length, names can't be equal */
105 ac = pkix_countArray((void**) ardns);
106 bc = pkix_countArray((void**) brdns);
107 if (ac != bc){
108 *pResult = PKIX_FALSE;
109 goto cleanup;
112 for (;;) {
113 PKIX_NULLCHECK_TWO(ardns, brdns);
114 ardn = *ardns++;
115 brdn = *brdns++;
116 if (!ardn) {
117 break;
120 PKIX_NULLCHECK_TWO(ardn, brdn);
121 aavas = ardn->avas;
122 bavas = brdn->avas;
124 /* if array of ava's not same length, names can't be equal */
125 ac = pkix_countArray((void**) aavas);
126 bc = pkix_countArray((void**) bavas);
127 if (ac != bc){
128 *pResult = PKIX_FALSE;
129 goto cleanup;
132 for (;;) {
133 PKIX_NULLCHECK_TWO(aavas, bavas);
134 aava = *aavas++;
135 bava = *bavas++;
136 if (!aava) {
137 break;
140 PKIX_X500NAME_DEBUG("\t\tCalling "
141 "SECITEM_CompareItem).\n");
142 rv = SECITEM_CompareItem(&aava->type, &bava->type);
143 if (rv != SECEqual){
144 *pResult = PKIX_FALSE;
145 goto cleanup;
148 PKIX_X500NAME_DEBUG("\t\tCalling "
149 "SECITEM_CompareItem).\n");
150 rv = SECITEM_CompareItem(&aava->value, &bava->value);
151 if (rv != SECEqual){
152 *pResult = PKIX_FALSE;
153 goto cleanup;
158 *pResult = (rv == SECEqual);
160 cleanup:
162 PKIX_RETURN(X500NAME);
166 * FUNCTION: pkix_pl_X500Name_ToString_Helper
167 * DESCRIPTION:
169 * Helper function that creates a string representation of the X500Name
170 * pointed to by "name" and stores it at "pString".
172 * PARAMETERS
173 * "name"
174 * Address of X500Name whose string representation is desired.
175 * Must be non-NULL.
176 * "pString"
177 * Address where object pointer will be stored. Must be non-NULL.
178 * "plContext" - Platform-specific context pointer.
179 * THREAD SAFETY:
180 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
181 * RETURNS:
182 * Returns NULL if the function succeeds.
183 * Returns a X500Name Error if the function fails in a non-fatal way.
184 * Returns a Fatal Error if the function fails in an unrecoverable way.
186 static PKIX_Error *
187 pkix_pl_X500Name_ToString_Helper(
188 PKIX_PL_X500Name *name,
189 PKIX_PL_String **pString,
190 void *plContext)
192 CERTName *nssDN = NULL;
193 char *utf8String = NULL;
194 PKIX_UInt32 utf8Length;
196 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_ToString_Helper");
197 PKIX_NULLCHECK_TWO(name, pString);
198 nssDN = name->nssDN;
200 PKIX_X500NAME_DEBUG("\t\tCalling CERT_NameToAscii).\n");
201 /* this should really be called CERT_NameToUTF8 */
202 utf8String = CERT_NameToAscii(nssDN);
203 if (!utf8String){
204 PKIX_ERROR(PKIX_CERTNAMETOASCIIFAILED);
207 PKIX_X500NAME_DEBUG("\t\tCalling PL_strlen).\n");
208 utf8Length = PL_strlen(utf8String);
210 PKIX_CHECK(PKIX_PL_String_Create
211 (PKIX_UTF8, utf8String, utf8Length, pString, plContext),
212 PKIX_STRINGCREATEFAILED);
214 cleanup:
216 PR_Free(utf8String);
218 PKIX_RETURN(X500NAME);
222 * FUNCTION: pkix_pl_X500Name_Destroy
223 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
225 static PKIX_Error *
226 pkix_pl_X500Name_Destroy(
227 PKIX_PL_Object *object,
228 void *plContext)
230 PKIX_PL_X500Name *name = NULL;
232 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_Destroy");
233 PKIX_NULLCHECK_ONE(object);
235 PKIX_CHECK(pkix_CheckType(object, PKIX_X500NAME_TYPE, plContext),
236 PKIX_OBJECTNOTANX500NAME);
238 name = (PKIX_PL_X500Name *)object;
240 PKIX_X500NAME_DEBUG("\t\tCalling CERT_DestroyName).\n");
241 CERT_DestroyName(name->nssDN);
242 name->nssDN = NULL;
244 cleanup:
246 PKIX_RETURN(X500NAME);
250 * FUNCTION: pkix_pl_X500Name_ToString
251 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
253 static PKIX_Error *
254 pkix_pl_X500Name_ToString(
255 PKIX_PL_Object *object,
256 PKIX_PL_String **pString,
257 void *plContext)
259 PKIX_PL_String *nameString = NULL;
260 PKIX_PL_X500Name *name = NULL;
262 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_toString");
263 PKIX_NULLCHECK_TWO(object, pString);
265 PKIX_CHECK(pkix_CheckType(object, PKIX_X500NAME_TYPE, plContext),
266 PKIX_OBJECTNOTANX500NAME);
268 name = (PKIX_PL_X500Name *)object;
270 PKIX_CHECK(pkix_pl_X500Name_ToString_Helper
271 (name, &nameString, plContext),
272 PKIX_X500NAMETOSTRINGHELPERFAILED);
274 *pString = nameString;
276 cleanup:
278 PKIX_RETURN(X500NAME);
282 * FUNCTION: pkix_pl_X500Name_Hashcode
283 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
285 static PKIX_Error *
286 pkix_pl_X500Name_Hashcode(
287 PKIX_PL_Object *object,
288 PKIX_UInt32 *pHashcode,
289 void *plContext)
291 PKIX_PL_X500Name *name = NULL;
292 SECItem *resultSecItem = NULL;
293 PRArenaPool *arena = NULL;
294 CERTName *nssDN = NULL;
295 PKIX_UInt32 nameHash;
296 SECItem *derBytes;
298 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_Hashcode");
299 PKIX_NULLCHECK_TWO(object, pHashcode);
301 PKIX_CHECK(pkix_CheckType(object, PKIX_X500NAME_TYPE, plContext),
302 PKIX_OBJECTNOTANX500NAME);
304 name = (PKIX_PL_X500Name *)object;
306 /* we hash over the bytes in the DER encoding */
308 nssDN = name->nssDN;
310 PKIX_X500NAME_DEBUG("\t\tCalling PORT_NewArena).\n");
311 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
312 if (arena == NULL) {
313 PKIX_ERROR(PKIX_PORTNEWARENAFAILED);
316 PKIX_X500NAME_DEBUG("\t\tCalling PORT_ArenaZNew).\n");
317 derBytes = PORT_ArenaZNew(arena, SECItem);
318 if (derBytes == NULL) {
319 PKIX_ERROR(PKIX_PORTARENAZNEWFAILED);
322 PKIX_X500NAME_DEBUG("\t\tCalling SEC_ASN1EncodeItem).\n");
323 resultSecItem =
324 SEC_ASN1EncodeItem(arena, derBytes, nssDN, CERT_NameTemplate);
326 if (resultSecItem == NULL){
327 PKIX_ERROR(PKIX_SECASN1ENCODEITEMFAILED);
330 PKIX_CHECK(pkix_hash
331 (derBytes->data, derBytes->len, &nameHash, plContext),
332 PKIX_HASHFAILED);
334 *pHashcode = nameHash;
336 cleanup:
338 if (arena){
339 /* Note that freeing the arena also frees derBytes */
340 PKIX_X500NAME_DEBUG("\t\tCalling PORT_FreeArena).\n");
341 PORT_FreeArena(arena, PR_FALSE);
344 PKIX_RETURN(X500NAME);
349 * FUNCTION: pkix_pl_X500Name_Equals
350 * (see comments for PKIX_PL_Equals_Callback in pkix_pl_system.h)
352 static PKIX_Error *
353 pkix_pl_X500Name_Equals(
354 PKIX_PL_Object *firstObject,
355 PKIX_PL_Object *secondObject,
356 PKIX_Boolean *pResult,
357 void *plContext)
359 PKIX_PL_X500Name *firstX500Name = NULL;
360 PKIX_PL_X500Name *secondX500Name = NULL;
361 PKIX_UInt32 secondType;
363 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_Equals");
364 PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult);
366 /* test that firstObject is an X500Name */
367 PKIX_CHECK(pkix_CheckType(firstObject, PKIX_X500NAME_TYPE, plContext),
368 PKIX_FIRSTOBJECTARGUMENTNOTANX500NAME);
371 * Since we know firstObject is an X500Name, if both references are
372 * identical, they must be equal
374 if (firstObject == secondObject){
375 *pResult = PKIX_TRUE;
376 goto cleanup;
380 * If secondObject isn't an X500Name, we don't throw an error.
381 * We simply return a Boolean result of FALSE
383 *pResult = PKIX_FALSE;
384 PKIX_CHECK(PKIX_PL_Object_GetType
385 (secondObject, &secondType, plContext),
386 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT);
387 if (secondType != PKIX_X500NAME_TYPE) goto cleanup;
389 firstX500Name = (PKIX_PL_X500Name *)firstObject;
390 secondX500Name = (PKIX_PL_X500Name *)secondObject;
392 /* we simply do byte comparison on DER encodings of DN's */
393 PKIX_CHECK(pkix_pl_X500Name_CompareDERBytes
394 (firstX500Name, secondX500Name, pResult, plContext),
395 PKIX_X500NAMECOMPAREDERBYTESFAILED);
397 cleanup:
399 PKIX_RETURN(X500NAME);
403 * FUNCTION: pkix_pl_X500Name_RegisterSelf
404 * DESCRIPTION:
405 * Registers PKIX_X500NAME_TYPE and its related functions with systemClasses[]
406 * THREAD SAFETY:
407 * Not Thread Safe - for performance and complexity reasons
409 * Since this function is only called by PKIX_PL_Initialize, which should
410 * only be called once, it is acceptable that this function is not
411 * thread-safe.
413 PKIX_Error *
414 pkix_pl_X500Name_RegisterSelf(void *plContext)
417 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
418 pkix_ClassTable_Entry entry;
420 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_RegisterSelf");
422 entry.description = "X500Name";
423 entry.destructor = pkix_pl_X500Name_Destroy;
424 entry.equalsFunction = pkix_pl_X500Name_Equals;
425 entry.hashcodeFunction = pkix_pl_X500Name_Hashcode;
426 entry.toStringFunction = pkix_pl_X500Name_ToString;
427 entry.comparator = NULL;
428 entry.duplicateFunction = pkix_duplicateImmutable;
430 systemClasses[PKIX_X500NAME_TYPE] = entry;
432 PKIX_RETURN(X500NAME);
435 /* --Public-Functions------------------------------------------------------- */
438 * FUNCTION: PKIX_PL_X500Name_Create (see comments in pkix_pl_pki.h)
440 PKIX_Error *
441 PKIX_PL_X500Name_Create(
442 PKIX_PL_String *stringRep,
443 PKIX_PL_X500Name **pName,
444 void *plContext)
446 PKIX_PL_X500Name *x500Name = NULL;
447 CERTName *nssDN = NULL;
448 char *utf8String = NULL;
449 PKIX_UInt32 utf8Length;
451 PKIX_ENTER(X500NAME, "PKIX_PL_X500Name_Create()");
452 PKIX_NULLCHECK_TWO(pName, stringRep);
455 * convert the input PKIX_PL_String to PKIX_UTF8_NULL_TERM.
456 * we need to use this format specifier because
457 * CERT_AsciiToName expects a NULL-terminated UTF8 string.
458 * Since UTF8 allow NUL characters in the middle of the
459 * string, this is buggy. However, as a workaround, using
460 * PKIX_UTF8_NULL_TERM gives us a NULL-terminated UTF8 string.
463 PKIX_CHECK(PKIX_PL_String_GetEncoded
464 (stringRep,
465 PKIX_UTF8_NULL_TERM,
466 (void **)&utf8String,
467 &utf8Length,
468 plContext),
469 PKIX_STRINGGETENCODEDFAILED);
471 PKIX_X500NAME_DEBUG("\t\tCalling CERT_AsciiToName).\n");
472 /* this should be really be called CERT_UTF8ToName */
473 nssDN = CERT_AsciiToName(utf8String);
474 if (nssDN == NULL) {
475 PKIX_ERROR(PKIX_COULDNOTCREATENSSDN);
478 /* create a PKIX_PL_X500Name object */
479 PKIX_CHECK(PKIX_PL_Object_Alloc
480 (PKIX_X500NAME_TYPE,
481 sizeof (PKIX_PL_X500Name),
482 (PKIX_PL_Object **)&x500Name,
483 plContext),
484 PKIX_COULDNOTCREATEX500NAMEOBJECT);
486 /* populate the nssDN field */
487 x500Name->nssDN = nssDN;
489 *pName = x500Name;
491 cleanup:
493 PKIX_FREE(utf8String);
495 if (nssDN && PKIX_ERROR_RECEIVED){
496 PKIX_X500NAME_DEBUG("\t\tCalling CERT_DestroyName).\n");
497 CERT_DestroyName(nssDN);
498 nssDN = NULL;
501 PKIX_RETURN(X500NAME);
505 * FUNCTION: PKIX_PL_X500Name_Match (see comments in pkix_pl_pki.h)
507 PKIX_Error *
508 PKIX_PL_X500Name_Match(
509 PKIX_PL_X500Name *firstX500Name,
510 PKIX_PL_X500Name *secondX500Name,
511 PKIX_Boolean *pResult,
512 void *plContext)
514 CERTName *firstName = NULL;
515 CERTName *secondName = NULL;
516 SECComparison cmpResult;
518 PKIX_ENTER(X500NAME, "PKIX_PL_X500Name_Equals");
519 PKIX_NULLCHECK_THREE(firstX500Name, secondX500Name, pResult);
521 if (firstX500Name == secondX500Name){
522 *pResult = PKIX_TRUE;
523 goto cleanup;
526 firstName = firstX500Name->nssDN;
527 secondName = secondX500Name->nssDN;
529 PKIX_NULLCHECK_TWO(firstName, secondName);
531 PKIX_X500NAME_DEBUG("\t\tCalling CERT_CompareName).\n");
532 cmpResult = CERT_CompareName(firstName, secondName);
534 *pResult = (cmpResult == SECEqual);
536 cleanup:
538 PKIX_RETURN(X500NAME);
542 * FUNCTION: pkix_pl_X500Name_GetSECName
544 * DESCRIPTION:
545 * Encodes as a SECItem the CERTName embodied by the X500Name object pointed
546 * to by "xname", using the arena pointed to by "arena", and stores the result
547 * at "pSECName". If the name cannot be successfully encoded, NULL is stored
548 * at "pSECName".
550 * PARAMETERS:
551 * "xname"
552 * Address of X500Name whose CERTName flag is to be encoded. Must be
553 * non-NULL.
554 * "arena"
555 * Address of the PRArenaPool to be used in the encoding, and in which
556 * "pSECName" will be allocated. Must be non-NULL.
557 * "pSECName"
558 * Address where result will be stored. Must be non-NULL.
559 * "plContext"
560 * Platform-specific context pointer.
562 * THREAD SAFETY:
563 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
565 * RETURNS:
566 * Returns NULL if the function succeeds.
567 * Returns a Fatal Error if the function fails in an unrecoverable way.
569 PKIX_Error *
570 pkix_pl_X500Name_GetSECName(
571 PKIX_PL_X500Name *xname,
572 PRArenaPool *arena,
573 SECItem **pSECName,
574 void *plContext)
577 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_GetCertName");
579 PKIX_NULLCHECK_THREE(xname, arena, pSECName);
582 * SEC_ASN1EncodeItem returns NULL if unsuccessful. We just
583 * store the NULL result.
585 PKIX_PL_NSSCALLRV(X500NAME, *pSECName, SEC_ASN1EncodeItem,
586 (arena, NULL, (void *)xname->nssDN, CERT_NameTemplate));
588 PKIX_RETURN(X500NAME);
592 * FUNCTION: pkix_pl_X500Name_CreateFromUtf8
594 * DESCRIPTION:
595 * Creates an X500Name object from the RFC1485 string representation pointed
596 * to by "stringRep", and stores the result at "pName". If the string cannot
597 * be successfully converted, a non-fatal error is returned.
599 * PARAMETERS:
600 * "stringRep"
601 * Address of the RFC1485 string to be converted. Must be non-NULL.
602 * "pName"
603 * Address where the X500Name result will be stored. Must be non-NULL.
604 * "plContext"
605 * Platform-specific context pointer.
607 * THREAD SAFETY:
608 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
610 * RETURNS:
611 * Returns NULL if the function succeeds.
612 * Returns an X500NAME Error if the function fails in a non-fatal way.
613 * Returns a Fatal Error if the function fails in an unrecoverable way.
615 PKIX_Error *
616 pkix_pl_X500Name_CreateFromUtf8(
617 char *stringRep,
618 PKIX_PL_X500Name **pName,
619 void *plContext)
621 PKIX_PL_X500Name *x500Name = NULL;
622 CERTName *nssDN = NULL;
624 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_CreateFromUtf8");
625 PKIX_NULLCHECK_TWO(pName, stringRep);
627 PKIX_PL_NSSCALLRV(X500NAME, nssDN, CERT_AsciiToName, (stringRep));
629 if (nssDN == NULL) {
630 PKIX_ERROR(PKIX_COULDNOTCREATENSSDN);
633 /* create a PKIX_PL_X500Name object */
634 PKIX_CHECK(PKIX_PL_Object_Alloc
635 (PKIX_X500NAME_TYPE,
636 sizeof (PKIX_PL_X500Name),
637 (PKIX_PL_Object **)&x500Name,
638 plContext),
639 PKIX_COULDNOTCREATEX500NAMEOBJECT);
641 /* populate the nssDN field */
642 x500Name->nssDN = nssDN;
644 *pName = x500Name;
646 cleanup:
648 if (nssDN && PKIX_ERROR_RECEIVED){
649 PKIX_X500NAME_DEBUG("\t\tCalling CERT_DestroyName).\n");
650 CERT_DestroyName(nssDN);
651 nssDN = NULL;
654 PKIX_RETURN(X500NAME);
658 * FUNCTION: pkix_pl_X500Name_GetCommonName
660 * DESCRIPTION:
661 * Extracts the CommonName component of the X500Name object pointed to by
662 * "xname", and stores the result at "pCommonName". If the CommonName cannot
663 * be successfully extracted, NULL is stored at "pCommonName".
665 * The returned string must be freed with PORT_Free.
667 * PARAMETERS:
668 * "xname"
669 * Address of X500Name whose CommonName is to be extracted. Must be
670 * non-NULL.
671 * "pCommonName"
672 * Address where result will be stored. Must be non-NULL.
673 * "plContext"
674 * Platform-specific context pointer.
676 * THREAD SAFETY:
677 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
679 * RETURNS:
680 * Returns NULL if the function succeeds.
681 * Returns a Fatal Error if the function fails in an unrecoverable way.
683 PKIX_Error *
684 pkix_pl_X500Name_GetCommonName(
685 PKIX_PL_X500Name *xname,
686 unsigned char **pCommonName,
687 void *plContext)
689 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_GetCommonName");
690 PKIX_NULLCHECK_TWO(xname, pCommonName);
692 PKIX_PL_NSSCALLRV
693 (X500NAME,
694 *pCommonName,
695 (unsigned char *)CERT_GetCommonName,
696 (xname->nssDN));
698 PKIX_RETURN(X500NAME);
702 * FUNCTION: pkix_pl_X500Name_GetCountryName
704 * DESCRIPTION:
705 * Extracts the CountryName component of the X500Name object pointed to by
706 * "xname", and stores the result at "pCountryName". If the CountryName cannot
707 * be successfully extracted, NULL is stored at "pCountryName".
709 * The returned string must be freed with PORT_Free.
711 * PARAMETERS:
712 * "xname"
713 * Address of X500Name whose CountryName is to be extracted. Must be
714 * non-NULL.
715 * "pCountryName"
716 * Address where result will be stored. Must be non-NULL.
717 * "plContext"
718 * Platform-specific context pointer.
720 * THREAD SAFETY:
721 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
723 * RETURNS:
724 * Returns NULL if the function succeeds.
725 * Returns a Fatal Error if the function fails in an unrecoverable way.
727 PKIX_Error *
728 pkix_pl_X500Name_GetCountryName(
729 PKIX_PL_X500Name *xname,
730 unsigned char **pCountryName,
731 void *plContext)
733 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_GetCountryName");
734 PKIX_NULLCHECK_TWO(xname, pCountryName);
736 PKIX_PL_NSSCALLRV
737 (X500NAME,
738 *pCountryName,
739 (unsigned char *)CERT_GetCountryName,
740 (xname->nssDN));
742 PKIX_RETURN(X500NAME);
746 * FUNCTION: pkix_pl_X500Name_GetOrgName
748 * DESCRIPTION:
749 * Extracts the OrganizationName component of the X500Name object pointed to by
750 * "xname", and stores the result at "pOrgName". If the OrganizationName cannot
751 * be successfully extracted, NULL is stored at "pOrgName".
753 * The returned string must be freed with PORT_Free.
755 * PARAMETERS:
756 * "xname"
757 * Address of X500Name whose OrganizationName is to be extracted. Must be
758 * non-NULL.
759 * "pOrgName"
760 * Address where result will be stored. Must be non-NULL.
761 * "plContext"
762 * Platform-specific context pointer.
764 * THREAD SAFETY:
765 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
767 * RETURNS:
768 * Returns NULL if the function succeeds.
769 * Returns a Fatal Error if the function fails in an unrecoverable way.
771 PKIX_Error *
772 pkix_pl_X500Name_GetOrgName(
773 PKIX_PL_X500Name *xname,
774 unsigned char **pOrgName,
775 void *plContext)
777 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_GetOrgName");
778 PKIX_NULLCHECK_TWO(xname, pOrgName);
780 PKIX_PL_NSSCALLRV
781 (X500NAME,
782 *pOrgName,
783 (unsigned char *)CERT_GetOrgName,
784 (xname->nssDN));
786 PKIX_RETURN(X500NAME);
788 PKIX_Error *
789 pkix_pl_X500Name_GetCERTName(
790 PKIX_PL_X500Name *xname,
791 CERTName **pCERTName,
792 void *plContext)
794 PKIX_ENTER(X500NAME, "pkix_pl_X500Name_GetCERTName");
795 PKIX_NULLCHECK_TWO(xname, pCERTName);
797 *pCERTName = xname->nssDN;
799 PKIX_RETURN(X500NAME);