Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / cmd / libpkix / pkix_pl / pki / test_crlentry.c
blob2a70d0069cf6e33199fdc6de2fa4f192a44c26e2
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 * test_crlentry.c
40 * Test CRLENTRY Type
44 #include "testutil.h"
45 #include "testutil_nss.h"
47 void *plContext = NULL;
49 void createCRLEntries(
50 char *dataDir,
51 char *crlInput,
52 PKIX_PL_CRL **pCrl,
53 PKIX_PL_CRLEntry **goodObject,
54 PKIX_PL_CRLEntry **equalObject,
55 PKIX_PL_CRLEntry **diffObject)
57 PKIX_PL_CRL *crl = NULL;
58 PKIX_PL_BigInt *firstSNBigInt = NULL;
59 PKIX_PL_BigInt *secondSNBigInt = NULL;
60 PKIX_PL_String *firstSNString = NULL;
61 PKIX_PL_String *secondSNString = NULL;
62 char *firstSNAscii = "010932";
63 char *secondSNAscii = "3039";
65 PKIX_TEST_STD_VARS();
67 subTest("PKIX_PL_CRL_Create <crl>");
68 crl = createCRL(dataDir, crlInput, plContext);
70 subTest("PKIX_PL_CRL_GetCRLEntryForSerialNumber");
71 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
72 PKIX_ESCASCII,
73 firstSNAscii,
74 PL_strlen(firstSNAscii),
75 &firstSNString,
76 plContext));
78 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
79 firstSNString,
80 &firstSNBigInt,
81 plContext));
83 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
84 crl, firstSNBigInt, goodObject, plContext));
86 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
87 crl, firstSNBigInt, equalObject, plContext));
89 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
90 PKIX_ESCASCII,
91 secondSNAscii,
92 PL_strlen(secondSNAscii),
93 &secondSNString,
94 plContext));
96 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
97 secondSNString,
98 &secondSNBigInt,
99 plContext));
101 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
102 crl, secondSNBigInt, diffObject, plContext));
106 *pCrl = crl;
108 cleanup:
109 PKIX_TEST_DECREF_AC(firstSNBigInt);
110 PKIX_TEST_DECREF_AC(secondSNBigInt);
111 PKIX_TEST_DECREF_AC(firstSNString);
112 PKIX_TEST_DECREF_AC(secondSNString);
113 PKIX_TEST_RETURN();
116 static void testGetReasonCode(
117 PKIX_PL_CRLEntry *goodObject)
119 PKIX_Int32 reasonCode = 0;
120 PKIX_Int32 expectedReasonCode = 260;
122 PKIX_TEST_STD_VARS();
124 subTest("PKIX_PL_CRLEntry_GetCRLEntryReasonCode");
126 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCRLEntryReasonCode(
127 goodObject, &reasonCode, plContext));
129 if (reasonCode != expectedReasonCode) {
130 testError("unexpected value of CRL Entry Reason Code");
131 (void) printf("Actual value:\t%d\n", reasonCode);
132 (void) printf("Expected value:\t%d\n", expectedReasonCode);
133 goto cleanup;
136 cleanup:
137 PKIX_TEST_RETURN();
140 static void
141 testCritExtensionsAbsent(PKIX_PL_CRLEntry *crlEntry)
143 PKIX_List *oidList = NULL;
144 PKIX_UInt32 numOids = 0;
146 PKIX_TEST_STD_VARS();
148 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCriticalExtensionOIDs
149 (crlEntry, &oidList, plContext));
151 PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
152 (oidList, &numOids, plContext));
153 if (numOids != 0){
154 pkixTestErrorMsg = "unexpected mismatch";
157 cleanup:
159 PKIX_TEST_DECREF_AC(oidList);
161 PKIX_TEST_RETURN();
164 static void
165 testGetCriticalExtensionOIDs(PKIX_PL_CRLEntry *goodObject)
167 subTest("PKIX_PL_CRL_GetCriticalExtensionOIDs "
168 "<CritExtensionsAbsent>");
169 testCritExtensionsAbsent(goodObject);
173 void printUsage(void) {
174 (void) printf("\nUSAGE:\ttest_crlentry <data-dir>\n\n");
177 /* Functional tests for CRLENTRY public functions */
179 int main(int argc, char *argv[]) {
180 PKIX_PL_CRL *crl = NULL;
181 PKIX_PL_CRLEntry *goodObject = NULL;
182 PKIX_PL_CRLEntry *equalObject = NULL;
183 PKIX_PL_CRLEntry *diffObject = NULL;
184 PKIX_UInt32 actualMinorVersion;
185 PKIX_UInt32 j = 0;
186 PKIX_Boolean useArenas = PKIX_FALSE;
188 char *dataDir = NULL;
189 char *goodInput = "crlgood.crl";
190 char *expectedAscii =
191 "\n\t[\n"
192 "\tSerialNumber: 010932\n"
193 "\tReasonCode: 260\n"
194 "\tRevocationDate: Fri Jan 07 15:09:10 2005\n"
195 "\tCritExtOIDs: (EMPTY)\n"
196 "\t]\n\t";
198 /* Note XXX serialnumber and reasoncode need debug */
200 PKIX_TEST_STD_VARS();
202 startTests("CRLEntry");
204 useArenas = PKIX_TEST_ARENAS_ARG(argv[1]);
206 PKIX_TEST_EXPECT_NO_ERROR(PKIX_Initialize
207 (PKIX_TRUE, /* nssInitNeeded */
208 useArenas,
209 PKIX_MAJOR_VERSION,
210 PKIX_MINOR_VERSION,
211 PKIX_MINOR_VERSION,
212 &actualMinorVersion,
213 &plContext));
215 if (argc < 1+j) {
216 printUsage();
217 return (0);
220 dataDir = argv[1+j];
222 createCRLEntries
223 (dataDir, goodInput, &crl, &goodObject, &equalObject, &diffObject);
225 PKIX_TEST_EQ_HASH_TOSTR_DUP
226 (goodObject,
227 equalObject,
228 diffObject,
229 NULL, /* expectedAscii, */
230 CRLENTRY,
231 PKIX_TRUE);
233 testGetReasonCode(goodObject);
235 testGetCriticalExtensionOIDs(goodObject);
237 cleanup:
239 PKIX_TEST_DECREF_AC(crl);
240 PKIX_TEST_DECREF_AC(goodObject);
241 PKIX_TEST_DECREF_AC(equalObject);
242 PKIX_TEST_DECREF_AC(diffObject);
244 PKIX_Shutdown(plContext);
246 PKIX_TEST_RETURN();
248 endTests("CRLEntry");
250 return (0);