summaryrefslogtreecommitdiff
path: root/nss/lib/libpkix/pkix/util/pkix_tools.h
blob: 1a4689da78c7155b3348e055276b2256a809f812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 * pkix_tools.h
 *
 * Header for Utility Functions and Macros
 *
 */

#ifndef _PKIX_TOOLS_H
#define _PKIX_TOOLS_H

#include "pkix.h"
#include <stddef.h>
#include <stdio.h>
#include "secport.h"
#include "prlong.h"

/* private PKIX system headers */
#include "pkix_basicconstraintschecker.h"
#include "pkix_buildresult.h"
#include "pkix_certchainchecker.h"
#include "pkix_certselector.h"
#include "pkix_comcertselparams.h"
#include "pkix_comcrlselparams.h"
#include "pkix_crlselector.h"
#include "pkix_error.h"
#include "pkix_expirationchecker.h"
#include "pkix_list.h"
#include "pkix_logger.h"
#include "pkix_namechainingchecker.h"
#include "pkix_nameconstraintschecker.h"
#include "pkix_policychecker.h"
#include "pkix_policynode.h"
#include "pkix_procparams.h"
#include "pkix_resourcelimits.h"
#include "pkix_revocationmethod.h"
#include "pkix_revocationchecker.h"
#include "pkix_crlchecker.h"
#include "pkix_ocspchecker.h"
#include "pkix_signaturechecker.h"
#include "pkix_store.h"
#include "pkix_targetcertchecker.h"
#include "pkix_validate.h"
#include "pkix_valresult.h"
#include "pkix_verifynode.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct pkixStdVarsStr {
    const char        *aMyFuncName;
    PKIX_Error        *aPkixErrorResult;
    PKIX_Error        *aPkixTempResult;
    PKIX_Error        *aPkixReturnResult;
    PKIX_ERRORCODE     aPkixErrorCode;
    PKIX_Boolean       aPkixErrorReceived;
    PKIX_Boolean       aPkixTempErrorReceived;
    PKIX_ERRORCLASS    aPkixErrorClass;
    PKIX_UInt32        aPkixType;
    PKIX_PL_Object    *aLockedObject;
    PKIX_List         *aPkixErrorList;
} PKIX_StdVars;

#ifdef PKIX_STDVARS_POINTER
#define myFuncName                  stdVars->aMyFuncName
#define pkixErrorResult             stdVars->aPkixErrorResult
#define pkixTempResult              stdVars->aPkixTempResult
#define pkixReturnResult            stdVars->aPkixReturnResult
#define pkixErrorCode               stdVars->aPkixErrorCode
#define pkixErrorReceived           stdVars->aPkixErrorReceived
#define pkixTempErrorReceived       stdVars->aPkixTempErrorReceived 
#define pkixErrorClass              stdVars->aPkixErrorClass
#define pkixType                    stdVars->aPkixType
#define lockedObject                stdVars->aLockedObject
#define pkixErrorList               stdVars->aPkixErrorList
#define stdVarsPtr                  stdVars
#else
#define myFuncName                  stdVars.aMyFuncName
#define pkixErrorResult             stdVars.aPkixErrorResult
#define pkixTempResult              stdVars.aPkixTempResult
#define pkixReturnResult            stdVars.aPkixReturnResult
#define pkixErrorCode               stdVars.aPkixErrorCode
#define pkixErrorReceived           stdVars.aPkixErrorReceived
#define pkixTempErrorReceived       stdVars.aPkixTempErrorReceived 
#define pkixErrorClass              stdVars.aPkixErrorClass
#define pkixType                    stdVars.aPkixType
#define lockedObject                stdVars.aLockedObject
#define pkixErrorList               stdVars.aPkixErrorList
#define stdVarsPtr                  &stdVars
#endif

extern PKIX_Error * PKIX_DoReturn(PKIX_StdVars * stdVars, 
                                  PKIX_ERRORCLASS errClass, 
                                  PKIX_Boolean doLogger,
                                  void * plContext);

extern PKIX_Error * PKIX_DoThrow(PKIX_StdVars * stdVars, 
                                 PKIX_ERRORCLASS errClass, 
                                 PKIX_ERRORCODE errCode,
                                 PKIX_ERRORCLASS overrideClass, 
                                 void * plContext);

extern void PKIX_DoAddError(PKIX_StdVars * stdVars, 
                            PKIX_Error * error,
                            void * plContext);

#ifdef PKIX_OBJECT_LEAK_TEST
extern PKIX_Error * pkix_CheckForGeneratedError(PKIX_StdVars * stdVars, 
                                                PKIX_ERRORCLASS errClass, 
                                                char * fnName,
                                                PKIX_Boolean *errorStateSet,
                                                void * plContext);
#endif /* PKIX_OBJECT_LEAK_TEST */

extern const PKIX_StdVars zeroStdVars;

extern PRLogModuleInfo *pkixLog;

/*
 * UTILITY MACROS
 * Documentation for these common utility macros can be found in the
 * Implementation Guidelines document (Section 4.3)
 *
 * In general, macros with multiple statements (or a single "if" statement)
 * use the "do {<body>} while (0)" technique in order to convert the multiple
 * statements into one statement, thus avoiding the dangling else problem.
 * For macros which ALWAYS exit with a "return" or "goto", there is no
 * need to use this technique (and it yields compiler warnings of "statement
 * not reached"), so we just use "{<body>}" to group the statements together.
 */

#if !defined (PKIX_OBJECT_LEAK_TEST)

#define PKIX_STD_VARS(funcName) \
    static const char cMyFuncName[] = {funcName}; \
    PKIX_StdVars      stdVars = zeroStdVars; \
    myFuncName = cMyFuncName


#else /* PKIX_OBJECT_LEAK_TEST */

extern char **fnStackNameArr;
extern PKIX_UInt32 *fnStackInvCountArr;
extern PKIX_UInt32  stackPosition;
extern PKIX_Boolean noErrorState;
extern PKIX_Boolean errorGenerated;
extern PKIX_Boolean runningLeakTest;
extern PLHashTable *fnInvTable;
extern PKIX_UInt32 testStartFnStackPosition;
extern char *errorFnStackString;

extern PLHashNumber PR_CALLBACK pkix_ErrorGen_Hash (const void *key);

#define PKIX_STD_VARS(funcName) \
    static const char cMyFuncName[] = {funcName}; \
    PKIX_StdVars      stdVars = zeroStdVars; \
    PKIX_Boolean      errorSetFlag = PKIX_FALSE; \
    myFuncName = cMyFuncName; \
    if (runningLeakTest) { \
        if (fnStackNameArr) { \
            fnStackInvCountArr[stackPosition] += 1; \
            stackPosition += 1; \
            fnStackInvCountArr[stackPosition] = 0; \
            fnStackNameArr[stackPosition] = (char*)myFuncName; \
            fnStackNameArr[stackPosition + 1] = NULL; \
            PR_LOG(pkixLog, 5, \
                    ("%s%*s+> %s(%d) - %s\n", (errorGenerated ? "*" : " "), \
                             stackPosition, " ", fnStackNameArr[stackPosition], \
                             stackPosition, myFuncName)); \
        } \
        do { \
            pkixErrorResult = pkix_CheckForGeneratedError(&stdVars, PKIX_MEM_ERROR, \
                                                          funcName, &errorSetFlag, \
                                                          plContext); \
            if (pkixErrorResult) { \
                 PR_LOG(pkixLog, 5, \
                    ("%s%*s<- %s(%d) - %s\n", (errorGenerated ? "*" : " "), \
                              stackPosition, " ", fnStackNameArr[stackPosition], \
                              stackPosition, myFuncName)); \
                 fnStackNameArr[stackPosition--] = NULL; \
                 if (errorSetFlag) { \
                       noErrorState = (noErrorState) ? PKIX_FALSE : PKIX_TRUE; \
                 } \
                 return pkixErrorResult; \
            } \
        } while (0); \
    }
#endif /* PKIX_OBJECT_LEAK_TEST */

#ifdef DEBUG
#define _PKIX_DEBUG_TRACE(cond, prefix, level) \
    do { \
	if (cond) { \
	    pkix_Logger_Check(pkixLoggersDebugTrace, myFuncName, \
	                      prefix, pkixType, level, plContext); \
	} \
    } while (0)
#else
#define _PKIX_DEBUG_TRACE(cond, prefix, level) 
#endif

#define _PKIX_LOG_ERROR(code, level) \
    { \
	if (pkixLoggersErrors) { \
	    pkix_Logger_CheckWithCode(pkixLoggersErrors, code, \
	                      NULL, pkixType, level, plContext); \
	} \
    }

#define PKIX_ENTER(type, funcName) \
    PKIX_STD_VARS(funcName); \
    pkixType = PKIX_ ## type ## _ERROR; \
    PKIX_DEBUG_ENTER(type); \
    _PKIX_DEBUG_TRACE(pkixLoggersDebugTrace, ">>>", PKIX_LOGGER_LEVEL_TRACE);

#define PKIX_ENTER_NO_LOGGER(type, funcName) \
    PKIX_STD_VARS(funcName); \
    pkixType = PKIX_ ## type ## _ERROR; \
    PKIX_DEBUG_ENTER(type);

#define PKIX_DEBUG_ENTER(type) \
    PKIX_ ## type ## _DEBUG_ARG("( Entering %s).\n", myFuncName)

#define PKIX_DEBUG_EXIT(type) \
    PKIX_ ## type ## _DEBUG_ARG("( Exiting %s).\n", myFuncName)

#define PKIX_OBJECT_UNLOCK(obj) \
    do { \
	if (obj && lockedObject == (PKIX_PL_Object *)(obj)){ \
	    pkixTempResult = \
		    PKIX_PL_Object_Unlock \
		    ((PKIX_PL_Object *)(obj), plContext); \
	    if (pkixTempResult) { \
		PKIX_DoAddError(stdVarsPtr, pkixTempResult, plContext); \
		pkixTempResult = NULL; \
	    } \
	    lockedObject = NULL; \
	} else { \
	    PORT_Assert(lockedObject == NULL); \
	} \
    } while (0)

#define PKIX_DECREF(obj) \
    do { \
	if (obj){ \
	    pkixTempResult = PKIX_PL_Object_DecRef \
			((PKIX_PL_Object *)(obj), plContext); \
	    if (pkixTempResult) { \
		PKIX_DoAddError(stdVarsPtr, pkixTempResult, plContext); \
		pkixTempResult = NULL; \
	    } \
	    obj = NULL; \
	} \
    } while (0)

#define PKIX_THROW(type, descNum) \
    return PKIX_DoThrow(&stdVars, (PKIX_ ## type ## _ERROR), descNum, \
                        pkixErrorClass, plContext);

#ifdef PKIX_OBJECT_LEAK_TEST
#define PKIX_RETURN(type) \
    if (runningLeakTest && fnStackNameArr) { \
        PR_LOG(pkixLog, 5, \
               ("%s%*s<- %s(%d) - %s\n", (errorGenerated ? "*" : " "), \
               stackPosition, " ", fnStackNameArr[stackPosition], \
               stackPosition, myFuncName)); \
        fnStackNameArr[stackPosition--] = NULL; \
        if (errorSetFlag) noErrorState = (noErrorState) ? PKIX_FALSE : PKIX_TRUE; \
    } \
    return PKIX_DoReturn(&stdVars, (PKIX_ ## type ## _ERROR), PKIX_TRUE, plContext);
#else
#define PKIX_RETURN(type) \
    return PKIX_DoReturn(&stdVars, (PKIX_ ## type ## _ERROR), PKIX_TRUE, plContext);
#endif /* PKIX_OBJECT_LEAK_TEST */


#if defined(DEBUG) && !defined(DEBUG_nb95248)
#define PKIX_RETURN_NO_LOGGER(type) \
    { \
	PKIX_OBJECT_UNLOCK(lockedObject); \
	if ((pkixErrorReceived) || (pkixErrorResult) || pkixErrorList) \
	    PKIX_THROW(type, pkixErrorCode); \
	PKIX_DEBUG_EXIT(type); \
	return NULL; \
    }
#else
#define PKIX_RETURN_NO_LOGGER(type) \
    return PKIX_DoReturn(&stdVars, (PKIX_ ## type ## _ERROR), PKIX_FALSE, plContext);
#endif

/* disable to disable ;-) */
/* #define WANT_TRACE_CHECK_FAILURES */

#ifdef WANT_TRACE_CHECK_FAILURES
#define TRACE_CHECK_FAILURE(what, errorstring) \
    if (pkixLog) { \
      PR_LOG(pkixLog, PR_LOG_DEBUG, \
        ("====> [%s] failed: %s\n", #what, errorstring)); \
    }
#else
#define TRACE_CHECK_FAILURE(what, errorstring)
#endif

#define PKIX_CHECK(func, descNum) \
    do { \
	pkixErrorResult = (func); \
	if (pkixErrorResult) { \
            TRACE_CHECK_FAILURE((func), PKIX_ErrorText[descNum]) \
	    pkixErrorClass = pkixErrorResult->errClass; \
	    pkixErrorCode = descNum; \
	    goto cleanup; \
	} \
    } while (0)

/* like PKIX_CHECK but without goto cleanup */
#define PKIX_CHECK_NO_GOTO(func, descNum) \
    do { \
	pkixErrorResult = (func); \
	if (pkixErrorResult) { \
            TRACE_CHECK_FAILURE((func), PKIX_ErrorText[descNum]) \
	    pkixErrorClass = pkixErrorResult->errClass; \
	    pkixErrorCode = descNum; \
	} \
    } while (0)

#define PKIX_CHECK_ONLY_FATAL(func, descNum) \
    do { \
	pkixTempErrorReceived = PKIX_FALSE; \
	pkixErrorResult = (func); \
	if (pkixErrorResult) { \
            TRACE_CHECK_FAILURE((func), PKIX_ErrorText[descNum]) \
	    pkixTempErrorReceived = PKIX_TRUE; \
	    pkixErrorClass = pkixErrorResult->errClass; \
            if (pkixErrorClass == PKIX_FATAL_ERROR) { \
	         goto cleanup; \
	    } \
	    PKIX_DECREF(pkixErrorResult); \
	} \
    } while (0)

#define PKIX_LOG_ERROR(descNum) \
    _PKIX_LOG_ERROR(descNum, PKIX_LOGGER_LEVEL_ERROR)

#define PKIX_ERROR(descNum) \
    { \
	PKIX_LOG_ERROR(descNum) \
	pkixErrorReceived = PKIX_TRUE; \
	pkixErrorCode = descNum; \
	goto cleanup; \
    }

#define PKIX_ERROR_ALLOC_ERROR() \
    { \
	PKIX_LOG_ERROR(PKIX_ALLOCERROR) \
	pkixErrorReceived = PKIX_TRUE; \
	pkixErrorResult = PKIX_ALLOC_ERROR(); \
	goto cleanup; \
    }

#define PKIX_ERROR_FATAL(descNum) \
    { \
	pkixErrorReceived = PKIX_TRUE; \
	pkixErrorCode = descNum; \
	pkixErrorClass = PKIX_FATAL_ERROR; \
	_PKIX_LOG_ERROR(pkixErrorCode, PKIX_LOGGER_LEVEL_FATALERROR); \
	goto cleanup; \
    }

#define PKIX_CHECK_FATAL(func, descNum) \
    do { \
	pkixErrorResult = (func); \
	if (pkixErrorResult) { \
                TRACE_CHECK_FAILURE((func), PKIX_ErrorText[descNum]) \
		pkixErrorReceived = PKIX_TRUE; \
		pkixErrorCode = descNum; \
		pkixErrorClass = PKIX_FATAL_ERROR; \
		_PKIX_LOG_ERROR(pkixErrorCode, PKIX_LOGGER_LEVEL_FATALERROR); \
		goto fatal; \
	} \
    } while (0)

#define PKIX_NULLCHECK_ONE(a) \
    do { \
	if ((a) == NULL){ \
	    pkixErrorReceived = PKIX_TRUE; \
	    pkixErrorCode = PKIX_NULLARGUMENT; \
	    PKIX_RETURN(FATAL); \
	} \
    } while (0)

#define PKIX_NULLCHECK_TWO(a, b) \
    do { \
	if (((a) == NULL) || ((b) == NULL)){ \
	    pkixErrorReceived = PKIX_TRUE; \
	    pkixErrorCode = PKIX_NULLARGUMENT; \
	    PKIX_RETURN(FATAL); \
	} \
    } while (0)

#define PKIX_NULLCHECK_THREE(a, b, c) \
    do { \
	if (((a) == NULL) || ((b) == NULL) || ((c) == NULL)){ \
	    pkixErrorReceived = PKIX_TRUE; \
	    pkixErrorCode = PKIX_NULLARGUMENT; \
	    PKIX_RETURN(FATAL); \
	} \
    } while (0)

#define PKIX_NULLCHECK_FOUR(a, b, c, d) \
    do { \
	if (((a) == NULL) || ((b) == NULL) || \
	    ((c) == NULL) || ((d) == NULL)){ \
	    pkixErrorReceived = PKIX_TRUE; \
	    pkixErrorCode = PKIX_NULLARGUMENT; \
	    PKIX_RETURN(FATAL); \
	} \
    } while (0)

#define PKIX_OBJECT_LOCK(obj) \
    do { \
	if (obj) { \
	    pkixTempResult = \
		PKIX_PL_Object_Lock((PKIX_PL_Object*)(obj), plContext); \
	    if (pkixTempResult) { \
		PKIX_DoAddError(stdVarsPtr, pkixTempResult, plContext); \
		pkixTempResult = NULL; \
		pkixErrorCode = PKIX_OBJECTLOCKFAILED; \
		goto cleanup; \
	    } \
	    lockedObject = (PKIX_PL_Object *)(obj); \
	} \
    } while (0)

#define PKIX_ERROR_CREATE(type, descNum, error) \
    { \
	pkixTempResult = (PKIX_Error*)pkix_Throw \
		(PKIX_ ## type ## _ERROR,  myFuncName, \
		descNum, PKIX_ ## type ## _ERROR, pkixErrorResult, \
		&error, plContext); \
	if (pkixTempResult) { \
	    error = pkixTempResult; \
	    pkixTempResult = NULL; \
	} \
    }
		

#define PKIX_ERROR_RECEIVED \
    (pkixErrorReceived || pkixErrorResult || pkixTempErrorReceived || \
     pkixErrorList)

#define PKIX_INCREF(obj) \
    do { \
	if (obj){ \
	    pkixTempResult = PKIX_PL_Object_IncRef \
			((PKIX_PL_Object *)(obj), plContext); \
	    if (pkixTempResult) { \
		PKIX_DoAddError(&stdVars, pkixTempResult, plContext); \
		pkixTempResult = NULL; \
		goto cleanup; \
	    } \
	} \
    } while (0)

#define PKIX_FREE(obj) \
    do { \
	if (obj) { \
	    pkixTempResult = PKIX_PL_Free((obj), plContext); \
	    if (pkixTempResult) { \
		PKIX_DoAddError(&stdVars, pkixTempResult, plContext); \
		pkixTempResult = NULL; \
	    } \
	    obj = NULL; \
	} \
    } while (0)

#define PKIX_EXACTLY_ONE_NULL(a, b) (((a) && !(b)) || ((b) && !(a)))

/* DIGIT MACROS */

#define PKIX_ISDIGIT(c) (((c) >= '0') && ((c) <= '9'))

#define PKIX_ISXDIGIT(c) \
    (PKIX_ISDIGIT(c) || ( (((c)|0x20) >= 'a') && (((c)|0x20) <= 'f') ))

#define PKIX_TOSTRING(a, b, c, d) \
    do { \
	int descNum; \
	if ((a) != NULL) { \
	    pkixErrorResult =  \
		PKIX_PL_Object_ToString((PKIX_PL_Object *)(a), (b), (c)); \
	    descNum = (d); \
	} else { \
	    pkixErrorResult =  \
		PKIX_PL_String_Create(PKIX_ESCASCII, "(null)", 0, (b), (c)); \
	    descNum = PKIX_STRINGCREATEFAILED; \
	} \
	PKIX_CHECK(pkixErrorResult, descNum); \
    } while (0)

#define PKIX_EQUALS(a, b, c, d, e) \
    do { \
	if ((a) != NULL && (b) != NULL) { \
	    PKIX_CHECK(PKIX_PL_Object_Equals\
			((PKIX_PL_Object *)(a), \
			(PKIX_PL_Object*)(b), \
			(c), \
			(d)), \
			(e)); \
	} else if ((a) == NULL && (b) == NULL) { \
	    *(c) = PKIX_TRUE; \
	} else { \
	    *(c) = PKIX_FALSE; \
	} \
    } while (0)

#define PKIX_HASHCODE(a, b, c, d) \
    do { \
	if ((a) != NULL) { \
	    PKIX_CHECK(PKIX_PL_Object_Hashcode\
		((PKIX_PL_Object *)(a), (b), (c)), (d)); \
	} else { \
	    *(b) = 0; \
	} \
    } while (0)

#define PKIX_DUPLICATE(a, b, c, d) \
    do { \
	if ((a) != NULL) { \
	    PKIX_CHECK(PKIX_PL_Object_Duplicate\
			((PKIX_PL_Object *)(a), \
			(PKIX_PL_Object **)(b), \
			(c)), \
			(d)); \
	} else { \
	    *(b) = (a); \
	} \
    } while (0)

/*
 * DEBUG MACROS
 *
 * Each type has an associated debug flag, which can
 * be set on the compiler line using "-D<debugflag>". For convenience,
 * "-DPKIX_DEBUGALL" turns on debug for all the components.
 *
 * If a type's debug flag is defined, then its two associated macros
 * are defined: PKIX_type_DEBUG(expr) and PKIX_type_DEBUG_ARG(expr, arg),
 * which call PKIX_DEBUG(expr) and PKIX_DEBUG_ARG(expr, arg) respectively,
 * which, in turn, enable standard and consistently formatted output.
 *
 * If a type's debug flag is not defined, the two associated macros
 * are defined as a NO-OP. As such, any PKIX_type_DEBUG or PKIX_type_DEBUG_ARG
 * macros for an undefined type will be stripped from the code during
 * pre-processing, thereby reducing code size.
 */

#ifdef PKIX_DEBUGALL
#define PKIX_REFCOUNTDEBUG                        1
#define PKIX_MEMDEBUG                             1
#define PKIX_MUTEXDEBUG                           1
#define PKIX_OBJECTDEBUG                          1
#define PKIX_STRINGDEBUG                          1
#define PKIX_OIDDEBUG                             1
#define PKIX_LISTDEBUG                            1
#define PKIX_ERRORDEBUG                           1
#define PKIX_BYTEARRAYDEBUG                       1
#define PKIX_RWLOCKDEBUG                          1
#define PKIX_BIGINTDEBUG                          1
#define PKIX_HASHTABLEDEBUG                       1
#define PKIX_X500NAMEDEBUG                        1
#define PKIX_GENERALNAMEDEBUG                     1
#define PKIX_PUBLICKEYDEBUG                       1
#define PKIX_CERTDEBUG                            1
#define PKIX_HTTPCLIENTDEBUG                      1
#define PKIX_DATEDEBUG                            1
#define PKIX_TRUSTANCHORDEBUG                     1
#define PKIX_PROCESSINGPARAMSDEBUG                1
#define PKIX_VALIDATEPARAMSDEBUG                  1
#define PKIX_VALIDATERESULTDEBUG                  1
#define PKIX_VALIDATEDEBUG                        1
#define PKIX_CERTCHAINCHECKERDEBUG                1
#define PKIX_REVOCATIONCHECKERDEBUG               1
#define PKIX_CERTSELECTORDEBUG                    1
#define PKIX_COMCERTSELPARAMSDEBUG                1
#define PKIX_TARGETCERTCHECKERSTATEDEBUG          1
#define PKIX_INITIALIZEPARAMSDEBUG                1
#define PKIX_CERTBASICCONSTRAINTSDEBUG            1
#define PKIX_CERTNAMECONSTRAINTSDEBUG             1
#define PKIX_CERTNAMECONSTRAINTSCHECKERSTATEDEBUG 1
#define PKIX_SUBJALTNAMECHECKERSTATEDEBUG         1

#define PKIX_CERTPOLICYQUALIFIERDEBUG             1
#define PKIX_CERTPOLICYINFODEBUG                  1
#define PKIX_CERTPOLICYNODEDEBUG                  1
#define PKIX_CERTPOLICYCHECKERSTATEDEBUG          1
#define PKIX_LIFECYCLEDEBUG                       1
#define PKIX_BASICCONSTRAINTSCHECKERSTATEDEBUG    1
#define PKIX_CRLDEBUG                             1
#define PKIX_CRLENTRYDEBUG                        1
#define PKIX_CRLSELECTORDEBUG                     1
#define PKIX_COMCRLSELPARAMSDEBUG                 1
#define PKIX_CERTSTOREDEBUG                       1
#define PKIX_COLLECTIONCERTSTORECONTEXTDEBUG      1
#define PKIX_DEFAULTCRLCHECKERSTATEDEBUG          1
#define PKIX_CERTPOLICYMAPDEBUG                   1
#define PKIX_BUILDDEBUG                           1
#define PKIX_BUILDRESULTDEBUG                     1
#define PKIX_FORWARDBUILDERSTATEDEBUG             1
#define PKIX_SIGNATURECHECKERSTATEDEBUG           1
#define PKIX_USERDEFINEDMODULESDEBUG              1
#define PKIX_CONTEXTDEBUG                         1
#define PKIX_DEFAULTREVOCATIONCHECKERDEBUG        1
#define PKIX_LDAPREQUESTDEBUG                     1
#define PKIX_LDAPRESPONSEDEBUG                    1
#define PKIX_LDAPCLIENTDEBUG                      1
#define PKIX_LDAPDEFAULTCLIENTDEBUG               1
#define PKIX_SOCKETDEBUG                          1
#define PKIX_RESOURCELIMITSDEBUG                  1
#define PKIX_LOGGERDEBUG                          1
#define PKIX_MONITORLOCKDEBUG                     1
#define PKIX_INFOACCESSDEBUG                      1
#define PKIX_AIAMGRDEBUG                          1
#define PKIX_OCSPCHECKERDEBUG                     1
#define PKIX_OCSPREQUESTDEBUG                     1
#define PKIX_OCSPRESPONSEDEBUG                    1
#define PKIX_HTTPDEFAULTCLIENTDEBUG               1
#define PKIX_HTTPCERTSTORECONTEXTDEBUG            1
#define PKIX_VERIFYNODEDEBUG                      1
#endif

/*
 * XXX Both PKIX_DEBUG and PKIX_DEBUG_ARG currently use printf.
 * This needs to be replaced with Loggers.
 */

#ifdef DEBUG
#define PKIX_DEBUG(expr) \
    do { \
	_PKIX_DEBUG_TRACE(pkixLoggersErrors, expr, PKIX_LOGGER_LEVEL_DEBUG); \
	(void) fprintf(stderr, "(%s: ", myFuncName); \
        (void) fprintf(stderr, expr);                \
    } while (0)
#else
#define PKIX_DEBUG(expr)
#endif

/* Logging doesn't support DEBUG with ARG: cannot convert control and arg */
#define PKIX_DEBUG_ARG(expr, arg) \
    do { \
	(void) printf("(%s: ", myFuncName); \
	(void) printf(expr, arg); \
    } while (0)

#if PKIX_FATALDEBUG
#define PKIX_FATAL_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_FATAL_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_FATAL_DEBUG(expr)
#define PKIX_FATAL_DEBUG_ARG(expr, arg)
#endif

#if PKIX_REFCOUNTDEBUG
#define PKIX_REF_COUNT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_REF_COUNT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_REF_COUNT_DEBUG(expr)
#define PKIX_REF_COUNT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_MEMDEBUG
#define PKIX_MEM_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_MEM_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_MEM_DEBUG(expr)
#define PKIX_MEM_DEBUG_ARG(expr, arg)
#endif

#if PKIX_MUTEXDEBUG
#define PKIX_MUTEX_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_MUTEX_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_MUTEX_DEBUG(expr)
#define PKIX_MUTEX_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OBJECTDEBUG
#define PKIX_OBJECT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OBJECT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OBJECT_DEBUG(expr)
#define PKIX_OBJECT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_ERRORDEBUG
#define PKIX_ERROR_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_ERROR_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_ERROR_DEBUG(expr)
#define PKIX_ERROR_DEBUG_ARG(expr, arg)
#endif

#if PKIX_STRINGDEBUG
#define PKIX_STRING_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_STRING_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_STRING_DEBUG(expr)
#define PKIX_STRING_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OIDDEBUG
#define PKIX_OID_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OID_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OID_DEBUG(expr)
#define PKIX_OID_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LISTDEBUG
#define PKIX_LIST_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LIST_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LIST_DEBUG(expr)
#define PKIX_LIST_DEBUG_ARG(expr, arg)
#endif

#if PKIX_RWLOCKDEBUG
#define PKIX_RWLOCK_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_RWLOCK_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_RWLOCK_DEBUG(expr)
#define PKIX_RWLOCK_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BYTEARRAYDEBUG
#define PKIX_BYTEARRAY_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BYTEARRAY_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BYTEARRAY_DEBUG(expr)
#define PKIX_BYTEARRAY_DEBUG_ARG(expr, arg)
#endif

#if PKIX_HASHTABLEDEBUG
#define PKIX_HASHTABLE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_HASHTABLE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_HASHTABLE_DEBUG(expr)
#define PKIX_HASHTABLE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_X500NAMEDEBUG
#define PKIX_X500NAME_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_X500NAME_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_X500NAME_DEBUG(expr)
#define PKIX_X500NAME_DEBUG_ARG(expr, arg)
#endif

#if PKIX_GENERALNAMEDEBUG
#define PKIX_GENERALNAME_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_GENERALNAME_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_GENERALNAME_DEBUG(expr)
#define PKIX_GENERALNAME_DEBUG_ARG(expr, arg)
#endif

#if PKIX_PUBLICKEYDEBUG
#define PKIX_PUBLICKEY_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_PUBLICKEY_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_PUBLICKEY_DEBUG(expr)
#define PKIX_PUBLICKEY_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTDEBUG
#define PKIX_CERT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERT_DEBUG(expr)
#define PKIX_CERT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CRLDPDEBUG
#define PKIX_CRLDP_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CRLDP_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CRLDP_DEBUG(expr)
#define PKIX_CRLDP_DEBUG_ARG(expr, arg)
#endif

#if PKIX_HTTPCLIENTDEBUG
#define PKIX_HTTPCLIENT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_HTTPCLIENT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_HTTPCLIENT_DEBUG(expr)
#define PKIX_HTTPCLIENT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BIGINTDEBUG
#define PKIX_BIGINT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BIGINT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BIGINT_DEBUG(expr)
#define PKIX_BIGINT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_DATEDEBUG
#define PKIX_DATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_DATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_DATE_DEBUG(expr)
#define PKIX_DATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_TRUSTANCHORDEBUG
#define PKIX_TRUSTANCHOR_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_TRUSTANCHOR_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_TRUSTANCHOR_DEBUG(expr)
#define PKIX_TRUSTANCHOR_DEBUG_ARG(expr, arg)
#endif

#if PKIX_PROCESSINGPARAMSDEBUG
#define PKIX_PROCESSINGPARAMS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_PROCESSINGPARAMS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_PROCESSINGPARAMS_DEBUG(expr)
#define PKIX_PROCESSINGPARAMS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_VALIDATEPARAMSDEBUG
#define PKIX_VALIDATEPARAMS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_VALIDATEPARAMS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_VALIDATEPARAMS_DEBUG(expr)
#define PKIX_VALIDATEPARAMS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_VALIDATERESULTDEBUG
#define PKIX_VALIDATERESULT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_VALIDATERESULT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_VALIDATERESULT_DEBUG(expr)
#define PKIX_VALIDATERESULT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_VALIDATEDEBUG
#define PKIX_VALIDATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_VALIDATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_VALIDATE_DEBUG(expr)
#define PKIX_VALIDATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BUILDDEBUG
#define PKIX_BUILD_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BUILD_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BUILD_DEBUG(expr)
#define PKIX_BUILD_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTCHAINCHECKERDEBUG
#define PKIX_CERTCHAINCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTCHAINCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTCHAINCHECKER_DEBUG(expr)
#define PKIX_CERTCHAINCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_REVOCATIONCHECKERDEBUG
#define PKIX_REVOCATIONCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_REVOCATIONCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_REVOCATIONCHECKER_DEBUG(expr)
#define PKIX_REVOCATIONCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_REVOCATIONMETHODDEBUG
#define PKIX_REVOCATIONMETHOD_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_REVOCATIONMETHOD_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_REVOCATIONMETHOD_DEBUG(expr)
#define PKIX_REVOCATIONMETHOD_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTSELECTORDEBUG
#define PKIX_CERTSELECTOR_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTSELECTOR_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTSELECTOR_DEBUG(expr)
#define PKIX_CERTSELECTOR_DEBUG_ARG(expr, arg)
#endif

#if PKIX_COMCERTSELPARAMSDEBUG
#define PKIX_COMCERTSELPARAMS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_COMCERTSELPARAMS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_COMCERTSELPARAMS_DEBUG(expr)
#define PKIX_COMCERTSELPARAMS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_TARGETCERTCHECKERSTATEDEBUG
#define PKIX_TARGETCERTCHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_TARGETCERTCHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_TARGETCERTCHECKERSTATE_DEBUG(expr)
#define PKIX_TARGETCERTCHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BASICCONSTRAINTSCHECKERSTATEDEBUG
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG(expr)
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_INITIALIZEPARAMSDEBUG
#define PKIX_INITIALIZEPARAMS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_INITIALIZEPARAMS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_INITIALIZEPARAMS_DEBUG(expr)
#define PKIX_INITIALIZEPARAMS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTBASICCONSTRAINTSDEBUG
#define PKIX_CERTBASICCONSTRAINTS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTBASICCONSTRAINTS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTBASICCONSTRAINTS_DEBUG(expr)
#define PKIX_CERTBASICCONSTRAINTS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTNAMECONSTRAINTSDEBUG
#define PKIX_CERTNAMECONSTRAINTS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTNAMECONSTRAINTS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTNAMECONSTRAINTS_DEBUG(expr)
#define PKIX_CERTNAMECONSTRAINTS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTNAMECONSTRAINTSCHECKERSTATEDEBUG
#define PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_DEBUG(expr)
#define PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_SUBJALTNAMECHECKERSTATEDEBUG
#define PKIX_SUBJALTNAMECHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_SUBJALTNAMECHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_SUBJALTNAMECHECKERSTATE_DEBUG(expr)
#define PKIX_SUBJALTNAMECHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTPOLICYQUALIFIERDEBUG
#define PKIX_CERTPOLICYQUALIFIER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTPOLICYQUALIFIER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTPOLICYQUALIFIER_DEBUG(expr)
#define PKIX_CERTPOLICYQUALIFIER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTPOLICYINFODEBUG
#define PKIX_CERTPOLICYINFO_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTPOLICYINFO_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTPOLICYINFO_DEBUG(expr)
#define PKIX_CERTPOLICYINFO_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTPOLICYNODEDEBUG
#define PKIX_CERTPOLICYNODE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTPOLICYNODE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTPOLICYNODE_DEBUG(expr)
#define PKIX_CERTPOLICYNODE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTPOLICYCHECKERSTATEDEBUG
#define PKIX_CERTPOLICYCHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTPOLICYCHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTPOLICYCHECKERSTATE_DEBUG(expr)
#define PKIX_CERTPOLICYCHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LIFECYCLEDEBUG
#define PKIX_LIFECYCLE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LIFECYCLE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LIFECYCLE_DEBUG(expr)
#define PKIX_LIFECYCLE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BASICCONSTRAINTSCHECKERSTATEDEBUG
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG(expr)
#define PKIX_BASICCONSTRAINTSCHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CRLDEBUG
#define PKIX_CRL_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CRL_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CRL_DEBUG(expr)
#define PKIX_CRL_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CRLENTRYDEBUG
#define PKIX_CRLENTRY_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CRLENTRY_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CRLENTRY_DEBUG(expr)
#define PKIX_CRLENTRY_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CRLSELECTORDEBUG
#define PKIX_CRLSELECTOR_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CRLSELECTOR_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CRLSELECTOR_DEBUG(expr)
#define PKIX_CRLSELECTOR_DEBUG_ARG(expr, arg)
#endif

#if PKIX_COMCRLSELPARAMSDEBUG
#define PKIX_COMCRLSELPARAMS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_COMCRLSELPARAMS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_COMCRLSELPARAMS_DEBUG(expr)
#define PKIX_COMCRLSELPARAMS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTSTOREDEBUG
#define PKIX_CERTSTORE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTSTORE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTSTORE_DEBUG(expr)
#define PKIX_CERTSTORE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_COLLECTIONCERTSTORECONTEXTDEBUG
#define PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG(expr)
#define PKIX_COLLECTIONCERTSTORECONTEXT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CRLCHECKERDEBUG
#define PKIX_CRLCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CRLCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CRLCHECKER_DEBUG(expr)
#define PKIX_CRLCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTPOLICYMAPDEBUG
#define PKIX_CERTPOLICYMAP_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTPOLICYMAP_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTPOLICYMAP_DEBUG(expr)
#define PKIX_CERTPOLICYMAP_DEBUG_ARG(expr, arg)
#endif

#if PKIX_BUILDRESULTDEBUG
#define PKIX_BUILDRESULT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_BUILDRESULT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_BUILDRESULT_DEBUG(expr)
#define PKIX_BUILDRESULT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_FORWARDBUILDERSTATEDEBUG
#define PKIX_FORWARDBUILDERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_FORWARDBUILDERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_FORWARDBUILDERSTATE_DEBUG(expr)
#define PKIX_FORWARDBUILDERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_SIGNATURECHECKERSTATEDEBUG
#define PKIX_SIGNATURECHECKERSTATE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_SIGNATURECHECKERSTATE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_SIGNATURECHECKERSTATE_DEBUG(expr)
#define PKIX_SIGNATURECHECKERSTATE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_USERDEFINEDMODULESDEBUG
#define PKIX_USERDEFINEDMODULES_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_USERDEFINEDMODULES_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_USERDEFINEDMODULES_DEBUG(expr)
#define PKIX_USERDEFINEDMODULES_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CONTEXTDEBUG
#define PKIX_CONTEXT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CONTEXT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CONTEXT_DEBUG(expr)
#define PKIX_CONTEXT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_REVOCATIONCHECKERDEBUG
#define PKIX_REVOCATIONCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_REVOCATIONCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_REVOCATIONCHECKER_DEBUG(expr)
#define PKIX_REVOCATIONCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LDAPREQUESTDEBUG
#define PKIX_LDAPREQUEST_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LDAPREQUEST_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LDAPREQUEST_DEBUG(expr)
#define PKIX_LDAPREQUEST_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LDAPRESPONSEDEBUG
#define PKIX_LDAPRESPONSE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LDAPRESPONSE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LDAPRESPONSE_DEBUG(expr)
#define PKIX_LDAPRESPONSE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LDAPCLIENTDEBUG
#define PKIX_LDAPCLIENT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LDAPCLIENT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LDAPCLIENT_DEBUG(expr)
#define PKIX_LDAPCLIENT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LDAPDEFAULTCLIENTDEBUG
#define PKIX_LDAPDEFAULTCLIENT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LDAPDEFAULTCLIENT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LDAPDEFAULTCLIENT_DEBUG(expr)
#define PKIX_LDAPDEFAULTCLIENT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_SOCKETDEBUG
#define PKIX_SOCKET_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_SOCKET_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_SOCKET_DEBUG(expr)
#define PKIX_SOCKET_DEBUG_ARG(expr, arg)
#endif

#if PKIX_RESOURCELIMITSDEBUG
#define PKIX_RESOURCELIMITS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_RESOURCELIMITS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_RESOURCELIMITS_DEBUG(expr)
#define PKIX_RESOURCELIMITS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_LOGGERDEBUG
#define PKIX_LOGGER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_LOGGER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_LOGGER_DEBUG(expr)
#define PKIX_LOGGER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_MONITORLOCKDEBUG
#define PKIX_MONITORLOCK_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_MONITORLOCK_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_MONITORLOCK_DEBUG(expr)
#define PKIX_MONITORLOCK_DEBUG_ARG(expr, arg)
#endif

#if PKIX_INFOACCESSDEBUG
#define PKIX_INFOACCESS_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_INFOACCESS_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_INFOACCESS_DEBUG(expr)
#define PKIX_INFOACCESS_DEBUG_ARG(expr, arg)
#endif

#if PKIX_AIAMGRDEBUG
#define PKIX_AIAMGR_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_AIAMGR_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_AIAMGR_DEBUG(expr)
#define PKIX_AIAMGR_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OCSPCHECKERDEBUG
#define PKIX_OCSPCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OCSPCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OCSPCHECKER_DEBUG(expr)
#define PKIX_OCSPCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OCSPCERTIDDEBUG
#define PKIX_OCSPCERTID_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OCSPCERTID_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OCSPCERTID_DEBUG(expr)
#define PKIX_OCSPCERTID_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OCSPREQUESTDEBUG
#define PKIX_OCSPREQUEST_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OCSPREQUEST_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OCSPREQUEST_DEBUG(expr)
#define PKIX_OCSPREQUEST_DEBUG_ARG(expr, arg)
#endif

#if PKIX_OCSPRESPONSEDEBUG
#define PKIX_OCSPRESPONSE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_OCSPRESPONSE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_OCSPRESPONSE_DEBUG(expr)
#define PKIX_OCSPRESPONSE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_HTTPDEFAULTCLIENTDEBUG
#define PKIX_HTTPDEFAULTCLIENT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_HTTPDEFAULTCLIENT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_HTTPDEFAULTCLIENT_DEBUG(expr)
#define PKIX_HTTPDEFAULTCLIENT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_HTTPCERTSTORECONTEXTDEBUG
#define PKIX_HTTPCERTSTORECONTEXT_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_HTTPCERTSTORECONTEXT_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_HTTPCERTSTORECONTEXT_DEBUG(expr)
#define PKIX_HTTPCERTSTORECONTEXT_DEBUG_ARG(expr, arg)
#endif

#if PKIX_VERIFYNODEDEBUG
#define PKIX_VERIFYNODE_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_VERIFYNODE_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_VERIFYNODE_DEBUG(expr)
#define PKIX_VERIFYNODE_DEBUG_ARG(expr, arg)
#endif

#if PKIX_EKUCHECKER
#define PKIX_EKUCHECKER_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_EKUCHECKER_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_EKUCHECKER_DEBUG(expr)
#define PKIX_EKUCHECKER_DEBUG_ARG(expr, arg)
#endif

#if PKIX_CERTVFYPKIXDEBUG
#define PKIX_CERTVFYPKIX_DEBUG(expr) \
        PKIX_DEBUG(expr)
#define PKIX_CERTVFYPKIX_DEBUG_ARG(expr, arg) \
        PKIX_DEBUG_ARG(expr, arg)
#else
#define PKIX_CERTVFYPKIX_DEBUG(expr)
#define PKIX_CERTVFYPKIX_DEBUG_ARG(expr, arg)
#endif

/*
 * All object types register themselves with the system using a
 * pkix_ClassTable_Entry, which consists of a set of functions for that
 * type and an ASCII string (char *) which is used by the default
 * ToStringCallback (if necessary). System types register themselves directly
 * when their respective PKIX_"type"_RegisterSelf functions are called.
 * User-defined types can be registered using PKIX_PL_Object_RegisterType.
 * (see comments in pkix_pl_system.h)
 */

typedef struct pkix_ClassTable_EntryStruct pkix_ClassTable_Entry;
struct pkix_ClassTable_EntryStruct {
        char *description;
        PKIX_UInt32 objCounter;
        PKIX_UInt32 typeObjectSize;
        PKIX_PL_DestructorCallback destructor;
        PKIX_PL_EqualsCallback equalsFunction;
        PKIX_PL_HashcodeCallback hashcodeFunction;
        PKIX_PL_ToStringCallback toStringFunction;
        PKIX_PL_ComparatorCallback comparator;
        PKIX_PL_DuplicateCallback duplicateFunction;
};

/*
 * PKIX_ERRORCLASSNAMES is an array of strings, with each string holding a
 * descriptive name for an error code. This is used by the default
 * PKIX_PL_Error_ToString function.
 */
extern const char *PKIX_ERRORCLASSNAMES[PKIX_NUMERRORCLASSES];

#define MAX_STACK_DEPTH         1000

extern PRLogModuleInfo *pkixLog;

#define PKIX_MAGIC_HEADER           LL_INIT(0xFEEDC0FF, 0xEEFACADE)
#define PKIX_MAGIC_HEADER_DESTROYED LL_INIT(0xBAADF00D, 0xDEADBEEF)

/* see source file for function documentation */

PKIX_Error *
pkix_IsCertSelfIssued(
        PKIX_PL_Cert *cert,
        PKIX_Boolean *pSelfIssued,
        void *plContext);

PKIX_Error *
pkix_Throw(
        PKIX_ERRORCLASS errClass,
        const char *funcName,
        PKIX_ERRORCODE errorTextCode,
        PKIX_ERRORCLASS overrideClass,
        PKIX_Error *cause,
        PKIX_Error **pError,
        void *plContext);

PKIX_Error *
pkix_CheckTypes(
        PKIX_PL_Object *first,
        PKIX_PL_Object *second,
        PKIX_UInt32 type,
        void *plContext);

PKIX_Error *
pkix_CheckType(
        PKIX_PL_Object *object,
        PKIX_UInt32 type,
        void *plContext);

PKIX_Error *
pkix_hash(
        const unsigned char *bytes,
        PKIX_UInt32 length,
        PKIX_UInt32 *hash,
        void *plContext);

PKIX_Error *
pkix_duplicateImmutable(
        PKIX_PL_Object *object,
        PKIX_PL_Object **pNewObject,
        void *plContext);

PKIX_UInt32
pkix_countArray(void **array);

PKIX_UInt32
pkix_hex2i(char c);

char
pkix_i2hex(char c);

PKIX_Boolean
pkix_isPlaintext(unsigned char c, PKIX_Boolean debug);

PKIX_Error *
pkix_CacheCertChain_Lookup(
        PKIX_PL_Cert* targetCert,
        PKIX_List* anchors,
        PKIX_PL_Date *testDate,
        PKIX_Boolean *pFound,
        PKIX_BuildResult **pBuildResult,
        void *plContext);

PKIX_Error *
pkix_CacheCertChain_Remove(
        PKIX_PL_Cert* targetCert,
        PKIX_List* anchors,
        void *plContext);

PKIX_Error *
pkix_CacheCertChain_Add(
        PKIX_PL_Cert* targetCert,
        PKIX_List* anchors,
        PKIX_PL_Date *validityDate,
        PKIX_BuildResult *buildResult,
        void *plContext);

PKIX_Error *
pkix_CacheCert_Lookup(
        PKIX_CertStore *store,
        PKIX_ComCertSelParams *certSelParams,
        PKIX_PL_Date *testDate,
        PKIX_Boolean *pFound,
        PKIX_List** pCerts,
        void *plContext);

PKIX_Error *
pkix_CacheCert_Add(
        PKIX_CertStore *store,
        PKIX_ComCertSelParams *certSelParams,
        PKIX_List* certs,
        void *plContext);

PKIX_Error *
pkix_CacheCrlEntry_Lookup(
        PKIX_CertStore *store,
        PKIX_PL_X500Name *certIssuer,
        PKIX_PL_BigInt *certSerialNumber,
        PKIX_Boolean *pFound,
        PKIX_List** pCrlEntryList,
        void *plContext);

PKIX_Error *
pkix_CacheCrlEntry_Add(
        PKIX_CertStore *store,
        PKIX_PL_X500Name *certIssuer,
        PKIX_PL_BigInt *certSerialNumber,
        PKIX_List* crlEntryList,
        void *plContext);

#ifdef PR_LOGGING
void
pkix_trace_dump_cert(
        const char *info, 
        PKIX_PL_Cert *cert, 
        void *plContext);
#endif

#ifdef __cplusplus
}
#endif

#endif /* _PKIX_TOOLS_H */