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 ***** */
40 * Test GeneralName Type
45 #include "testutil_nss.h"
47 static void *plContext = NULL;
50 createGeneralNames(PKIX_UInt32 nameType, char *goodInput, char *diffInput,
51 PKIX_PL_GeneralName **goodName,
52 PKIX_PL_GeneralName **equalName,
53 PKIX_PL_GeneralName **diffName){
55 subTest("PKIX_PL_GeneralName_Create <goodName>");
56 *goodName = createGeneralName(nameType, goodInput, plContext);
58 subTest("PKIX_PL_GeneralName_Create <equalName>");
59 *equalName = createGeneralName(nameType, goodInput, plContext);
61 subTest("PKIX_PL_GeneralName_Create <diffName>");
62 *diffName = createGeneralName(nameType, diffInput, plContext);
67 testDestroy(void *goodObject, void *equalObject, void *diffObject)
71 subTest("PKIX_PL_GeneralName_Destroy");
73 PKIX_TEST_DECREF_BC(goodObject);
74 PKIX_TEST_DECREF_BC(equalObject);
75 PKIX_TEST_DECREF_BC(diffObject);
83 static void testNameType
84 (PKIX_UInt32 nameType, char *goodInput, char *diffInput, char *expectedAscii){
86 PKIX_PL_GeneralName *goodName = NULL;
87 PKIX_PL_GeneralName *equalName = NULL;
88 PKIX_PL_GeneralName *diffName = NULL;
90 createGeneralNames(nameType, goodInput, diffInput,
91 &goodName, &equalName, &diffName);
93 PKIX_TEST_EQ_HASH_TOSTR_DUP
101 testDestroy(goodName, equalName, diffName);
104 int test_generalname(int argc, char *argv[]) {
106 char *goodInput = NULL;
107 char *diffInput = NULL;
108 PKIX_UInt32 actualMinorVersion;
111 PKIX_TEST_STD_VARS();
113 startTests("GeneralName");
115 PKIX_TEST_EXPECT_NO_ERROR(
116 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
118 goodInput = "john@sun.com";
119 diffInput = "john@labs.com";
120 testNameType(PKIX_RFC822_NAME, goodInput, diffInput, goodInput);
122 goodInput = "example1.com";
123 diffInput = "ex2.net";
124 testNameType(PKIX_DNS_NAME, goodInput, diffInput, goodInput);
126 goodInput = "cn=yassir, ou=labs, o=sun, c=us";
127 diffInput = "cn=alice, ou=labs, o=sun, c=us";
128 testNameType(PKIX_DIRECTORY_NAME,
131 "CN=yassir,OU=labs,O=sun,C=us");
133 goodInput = "http://example1.com";
134 diffInput = "http://ex2.net";
135 testNameType(PKIX_URI_NAME, goodInput, diffInput, goodInput);
137 goodInput = "1.2.840.11";
138 diffInput = "1.2.840.115349";
139 testNameType(PKIX_OID_NAME, goodInput, diffInput, goodInput);
142 * We don't support creating PKIX_EDIPARTY_NAME,
143 * PKIX_IP_NAME, OTHER_NAME, X400_ADDRESS from strings
148 PKIX_Shutdown(plContext);
152 endTests("GeneralName");