summaryrefslogtreecommitdiff
path: root/security/nss/lib/libpkix/include/pkix_util.h
blob: e42f608c17a7a1734d17af60c19be84a3a67bb55 (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
/* 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/. */
/*
 * These functions provide support for a number of other functions
 * by creating and manipulating data structures used by those functions.
 *
 */

#ifndef _PKIX_UTIL_H
#define _PKIX_UTIL_H

#include "pkixt.h"

#ifdef __cplusplus
extern "C" {
#endif

/* General
 *
 * Please refer to the libpkix Programmer's Guide for detailed information
 * about how to use the libpkix library. Certain key warnings and notices from
 * that document are repeated here for emphasis.
 *
 * All identifiers in this file (and all public identifiers defined in
 * libpkix) begin with "PKIX_". Private identifiers only intended for use
 * within the library begin with "pkix_".
 *
 * A function returns NULL upon success, and a PKIX_Error pointer upon failure.
 *
 * Unless otherwise noted, for all accessor (gettor) functions that return a
 * PKIX_PL_Object pointer, callers should assume that this pointer refers to a
 * shared object. Therefore, the caller should treat this shared object as
 * read-only and should not modify this shared object. When done using the
 * shared object, the caller should release the reference to the object by
 * using the PKIX_PL_Object_DecRef function.
 *
 * While a function is executing, if its arguments (or anything referred to by
 * its arguments) are modified, free'd, or destroyed, the function's behavior
 * is undefined.
 *
 */

/* PKIX_Logger
 *
 * PKIX_Loggers provide a standard way for the caller to insert custom logging
 * facilities. These are used by libpkix to log errors, debug information,
 * status, etc. The LogCallback allows custom logging to take place.
 * Additionally, a Logger can be initialized with a loggerContext, which is
 * where the caller can specify configuration data such as the name of a
 * logfile or database. Note that this loggerContext must be a PKIX_PL_Object,
 * allowing it to be reference-counted and allowing it to provide the standard
 * PKIX_PL_Object functions (Equals, Hashcode, ToString, Compare, Duplicate).
 *
 * Once the caller has created the Logger object(s) (and set the loggerContext
 * (if any) and the Log callback), the caller then registers these Loggers
 * with the system by calling PKIX_SetLoggers or PKIX_AddLogger. All log
 * entries will then be logged using the specified Loggers. If multiple
 * Loggers are specified, every log entry will be logged with each of them.
 *
 * XXX Maybe give some guidance somewhere on how much detail each logging
 * level should have and where component boundaries should be. Maybe in
 * Implementor's Guide or Programmer's Guide.
 */

#define PKIX_LOGGER_LEVEL_TRACE                5
#define PKIX_LOGGER_LEVEL_DEBUG                4
#define PKIX_LOGGER_LEVEL_WARNING              3
#define PKIX_LOGGER_LEVEL_ERROR                2
#define PKIX_LOGGER_LEVEL_FATALERROR           1

#define PKIX_LOGGER_LEVEL_MAX                  5

/*
 * FUNCTION: PKIX_Logger_LogCallback
 * DESCRIPTION:
 *
 *  This callback function logs a log entry containing the String pointed to
 *  by "message", the integer value of logLevel, and the String pointed to by
 *  "logComponent". A log entry can be associated with a particular log
 *  level (i.e. level 3) and a particular log component (i.e. "CertStore").
 *  For example, someone reading the log may only be interested in very general
 *  log entries so they look only for log level 1. Similarly, they may only be
 *  interested in log entries pertaining to the CertStore component so they
 *  look only for that log component. This function can be used before calling
 *  PKIX_Initialize.
 *
 * PARAMETERS:
 *  "logger"
 *      Address of logger whose LogCallback is to be used. Must be non-NULL.
 *  "message"
 *      Address of String that is to be logged used "logger". Must be non-NULL.
 *  "logLevel"
 *      Integer value representing the log level for this entry. The higher the
 *      level, the more detail. Must be non-NULL.
 *  "logComponent"
 *      PKIXERRORNUM value (defined in pkixt.h) designating the log component
 *      for this entry.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe
 *
 *  Multiple threads must be able to safely call this function without
 *  worrying about conflicts, even if they're operating on the same objects.
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
typedef PKIX_Error *
(*PKIX_Logger_LogCallback)(
        PKIX_Logger *logger,
        PKIX_PL_String *message,
        PKIX_UInt32 logLevel,
        PKIX_ERRORCLASS logComponent,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_Create
 * DESCRIPTION:
 *
 *  Creates a new Logger using the Object pointed to by "loggerContext"
 *  (if any) and stores it at "pLogger". The new Logger uses the LogCallback
 *  pointed to by "callback". The Logger's maximum logging level is initially
 *  set to a very high level and its logging component is set to NULL (all
 *  components).
 *
 * PARAMETERS:
 *  "callback"
 *      The LogCallback function to be used. Must be non-NULL.
 *  "loggerContext"
 *      Address of Object representing the Logger's context (if any).
 *  "pLogger"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_Create(
        PKIX_Logger_LogCallback callback,
        PKIX_PL_Object *loggerContext,
        PKIX_Logger **pLogger,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_GetLogCallback
 * DESCRIPTION:
 *
 *  Retrieves a pointer to "logger's" Log callback function and puts it in
 *  "pCallback".
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose Log callback is desired. Must be non-NULL.
 *  "pCallback"
 *      Address where Log callback function pointer will be stored.
 *      Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_GetLogCallback(
        PKIX_Logger *logger,
        PKIX_Logger_LogCallback *pCallback,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_GetLoggerContext
 * DESCRIPTION:
 *
 *  Retrieves a pointer to a PKIX_PL_Object representing the context (if any)
 *  of the Logger pointed to by "logger" and stores it at "pLoggerContext".
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose context is to be stored. Must be non-NULL.
 *  "pLoggerContext"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_GetLoggerContext(
        PKIX_Logger *logger,
        PKIX_PL_Object **pLoggerContext,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_GetMaxLoggingLevel
 * DESCRIPTION:
 *
 *  Retrieves a pointer to a PKIX_UInt32 representing the maximum logging
 *  level of the Logger pointed to by "logger" and stores it at "pLevel". Only
 *  log entries whose log level is less than or equal to this maximum logging
 *  level will be logged.
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose maximum logging level is to be stored.
 *      Must be non-NULL.
 *  "pLevel"
 *      Address where PKIX_UInt32 will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_GetMaxLoggingLevel(
        PKIX_Logger *logger,
        PKIX_UInt32 *pLevel,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_SetMaxLoggingLevel
 * DESCRIPTION:
 *
 *  Sets the maximum logging level of the Logger pointed to by "logger" with
 *  the integer value of "level".
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose maximum logging level is to be set.
 *      Must be non-NULL.
 *  "level"
 *      Maximum logging level to be set
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "logger"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_SetMaxLoggingLevel(
        PKIX_Logger *logger,
        PKIX_UInt32 level,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_GetLoggingComponent
 * DESCRIPTION:
 *
 *  Retrieves a pointer to a String representing the logging component of the
 *  Logger pointed to by "logger" and stores it at "pComponent". Only log
 *  entries whose log component matches the specified logging component will
 *  be logged.
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose logging component is to be stored.
 *      Must be non-NULL.
 *  "pComponent"
 *      Address where PKIXERRORNUM will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_GetLoggingComponent(
        PKIX_Logger *logger,
        PKIX_ERRORCLASS *pComponent,
        void *plContext);

/*
 * FUNCTION: PKIX_Logger_SetLoggingComponent
 * DESCRIPTION:
 *
 *  Sets the logging component of the Logger pointed to by "logger" with the
 *  PKIXERRORNUM pointed to by "component". To match a small set of components,
 *  create a Logger for each.
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger whose logging component is to be set.
 *      Must be non-NULL.
 *  "component"
 *      PKIXERRORNUM value representing logging component to be set.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "logger"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Logger_SetLoggingComponent(
        PKIX_Logger *logger,
        PKIX_ERRORCLASS component,
        void *plContext);

/*
 * FUNCTION: PKIX_GetLoggers
 * DESCRIPTION:
 *
 *  Retrieves a pointer to the List of Loggers (if any) being used for logging
 *  by libpkix and stores it at "pLoggers". If no loggers are being used, this
 *  function stores an empty List at "pLoggers".
 *
 *  Note that the List returned by this function is immutable.
 *
 * PARAMETERS:
 *  "pLoggers"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_GetLoggers(
        PKIX_List **pLoggers,  /* list of PKIX_Logger */
        void *plContext);

/*
 * FUNCTION: PKIX_SetLoggers
 * DESCRIPTION:
 *
 *  Sets the Loggers to be used by libpkix to the List of Loggers pointed to
 *  by "loggers". If "loggers" is NULL, no Loggers will be used.
 *
 * PARAMETERS:
 *  "loggers"
 *      Address of List of Loggers to be set. NULL for no Loggers.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_SetLoggers(
        PKIX_List *loggers,  /* list of PKIX_Logger */
        void *plContext);

/*
 * FUNCTION: PKIX_AddLogger
 * DESCRIPTION:
 *
 *  Adds the Logger pointed to by "logger" to the List of Loggers used by
 *  libpkix.
 *
 * PARAMETERS:
 *  "logger"
 *      Address of Logger to be added. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Logger Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_AddLogger(
        PKIX_Logger *logger,
        void *plContext);

/* Functions pertaining to the PKIX_Error type */

/* Error
 *
 * An Error object is returned by a function upon encountering some error
 * condition. Each Error is associated with an errorCode specified in pkixt.h.
 * The remaining components of an Error are optional. An Error's description
 * specifies a text message describing the Error. An Error's supplementary info
 * specifies additional information that might be useful. Finally, an Error's
 * cause specifies the underlying Error (if any) that resulted in this Error
 * being returned, thereby allowing Errors to be chained so that an entire
 * "error stack trace" can be represented. Once created, an Error is immutable.
 *
 * Note that the Error's supplementary info must be an Object (although any
 * object type), allowing it to be reference-counted and allowing it to
 * provide the standard Object functions (Equals, Hashcode, ToString, Compare,
 * Duplicate).
 *
 * Errors are classified as either being fatal or non-fatal. If a function
 * fails in an unrecoverable way, it returns an Error whose errorCode is
 * PKIX_FATAL_ERROR. If such an error is encountered, the caller should
 * not attempt to recover since something seriously wrong has happened
 * (e.g. corrupted memory, memory finished, etc.). All other errorCodes
 * are considered non-fatal errors and can be handled by the caller as they
 * see fit.
 */

/*
 * FUNCTION: PKIX_Error_Create
 * DESCRIPTION:
 *
 *  Creates a new Error using the value of "errorCode", the Error pointed to by
 *  "cause" (if any), the Object pointed to by "info" (if any), and the String
 *  pointed to by "desc" and stores it at "pError". If any error occurs during
 *  error allocation, it will be returned without chaining, since new errors
 *  cannot be created. Once created, an Error is immutable.
 *
 * PARAMETERS:
 *  "errorCode"
 *      Value of error code.
 *  "cause"
 *      Address of Error representing error's cause.
 *      NULL if none or unspecified.
 *  "info"
 *      Address of Object representing error's supplementary information.
 *      NULL if none.
 *  "desc"
 *      Address of String representing error's description. NULL if none.
 *  "pError"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_Create(
        PKIX_ERRORCLASS errClass,
        PKIX_Error *cause,
        PKIX_PL_Object *info,
        PKIX_ERRORCODE errCode,
        PKIX_Error **pError,
        void *plContext);

/*
 * FUNCTION: PKIX_Error_GetErrorClass
 * DESCRIPTION:
 *
 *  Retrieves the error class of the Error pointed to by "error" and 
 *  stores it at "pClass". Supported error codes are defined in pkixt.h.
 *
 * PARAMETERS:
 *  "error"
 *      Address of Error whose error code is desired. Must be non-NULL.
 *  "pClass"
 *      Address where PKIX_UInt32 will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_GetErrorClass(
        PKIX_Error *error,
        PKIX_ERRORCLASS *pClass,
        void *plContext);

/*
 * FUNCTION: PKIX_Error_GetErrorCode
 * DESCRIPTION:
 *
 *  Retrieves the error code of the Error pointed to by "error" and 
 *  stores it at "pCode". Supported error codes are defined in pkixt.h.
 *
 * PARAMETERS:
 *  "error"
 *      Address of Error whose error code is desired. Must be non-NULL.
 *  "pCode"
 *      Address where PKIX_UInt32 will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_GetErrorCode(
        PKIX_Error *error,
        PKIX_ERRORCODE *pCode,
        void *plContext);

/*
 * FUNCTION: PKIX_Error_GetCause
 * DESCRIPTION:
 *
 *  Retrieves the cause of the Error pointed to by "error" and stores it at
 *  "pCause". If no cause was specified, NULL will be stored at "pCause".
 *
 * PARAMETERS:
 *  "error"
 *      Address of Error whose cause is desired. Must be non-NULL.
 *  "pCause"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_GetCause(
        PKIX_Error *error,
        PKIX_Error **pCause,
        void *plContext);

/*
 * FUNCTION: PKIX_Error_GetSupplementaryInfo
 * DESCRIPTION:
 *
 *  Retrieves the supplementary info of the Error pointed to by "error" and
 *  stores it at "pInfo".
 *
 * PARAMETERS:
 *  "error"
 *      Address of Error whose info is desired. Must be non-NULL.
 *  "pInfo"
 *      Address where info pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_GetSupplementaryInfo(
        PKIX_Error *error,
        PKIX_PL_Object **pInfo,
        void *plContext);

/*
 * FUNCTION: PKIX_Error_GetDescription
 * DESCRIPTION:
 *
 *  Retrieves the description of the Error pointed to by "error" and stores it
 *  at "pDesc". If no description was specified, NULL will be stored at
 *  "pDesc".
 *
 * PARAMETERS:
 *  "error"
 *      Address of Error whose description is desired. Must be non-NULL.
 *  "pDesc"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns an Error Error if the function fails in a non-fatal way.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_Error_GetDescription(
        PKIX_Error *error,
        PKIX_PL_String **pDesc,
        void *plContext);

/* PKIX_List
 *
 * Represents a collection of items. NULL is considered a valid item.
 */

/*
 * FUNCTION: PKIX_List_Create
 * DESCRIPTION:
 *
 *  Creates a new List and stores it at "pList". The List is initially empty
 *  and holds no items. To initially add items to the List, use
 *  PKIX_List_AppendItem
 *
 * PARAMETERS:
 *  "pList"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_Create(
        PKIX_List **pList,
        void *plContext);

/*
 * FUNCTION: PKIX_List_SetImmutable
 * DESCRIPTION:
 *
 *  Sets the List pointed to by "list" to be immutable. If a caller tries to
 *  change a List after it has been marked immutable (i.e. by calling
 *  PKIX_List_AppendItem, PKIX_List_InsertItem, PKIX_List_SetItem, or
 *  PKIX_List_DeleteItem), an Error is returned.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to be marked immutable. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "list"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_SetImmutable(
        PKIX_List *list,
        void *plContext);

/*
 * FUNCTION: PKIX_List_IsImmutable
 * DESCRIPTION:
 *
 *  Checks whether the List pointed to by "list" is immutable and stores
 *  the Boolean result at "pImmutable". If a caller tries to change a List
 *  after it has been marked immutable (i.e. by calling PKIX_List_AppendItem,
 *  PKIX_List_InsertItem, PKIX_List_SetItem, or PKIX_List_DeleteItem), an
 *  Error is returned.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List whose immutability is to be determined.
 *      Must be non-NULL.
 *  "pImmutable"
 *      Address where PKIX_Boolean will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_IsImmutable(
        PKIX_List *list,
        PKIX_Boolean *pImmutable,
        void *plContext);

/*
 * FUNCTION: PKIX_List_GetLength
 * DESCRIPTION:
 *
 *  Retrieves the length of the List pointed to by "list" and stores it at
 *  "pLength".
 *
 * PARAMETERS:
 *  "list"
 *      Address of List whose length is desired. Must be non-NULL.
 *  "pLength"
 *      Address where PKIX_UInt32 will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_GetLength(
        PKIX_List *list,
        PKIX_UInt32 *pLength,
        void *plContext);

/*
 * FUNCTION: PKIX_List_IsEmpty
 * DESCRIPTION:
 *
 *  Checks whether the List pointed to by "list" is empty and stores
 *  the Boolean result at "pEmpty".
 *
 * PARAMETERS:
 *  "list"
 *      Address of List whose emptiness is to be determined. Must be non-NULL.
 *  "pEmpty"
 *      Address where PKIX_Boolean will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_IsEmpty(
        PKIX_List *list,
        PKIX_Boolean *pEmpty,
        void *plContext);

/*
 * FUNCTION: PKIX_List_AppendItem
 * DESCRIPTION:
 *
 *  Appends the Object pointed to by "item" after the last non-NULL item in
 *  List pointed to by "list", if any. Note that a List may validly contain
 *  NULL items. Appending "c" into the List ("a", NULL, "b", NULL) will result
 *  in ("a", NULL, "b", "c").
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to append to. Must be non-NULL.
 *  "item"
 *      Address of new item to append.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "list"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_AppendItem(
        PKIX_List *list,
        PKIX_PL_Object *item,
        void *plContext);

/*
 * FUNCTION: PKIX_List_InsertItem
 * DESCRIPTION:
 *
 *  Inserts the Object pointed to by "item" into the List pointed to by "list"
 *  at the given "index". The index counts from zero and must be less than the
 *  List's length. Existing list entries at or after this index will be moved
 *  to the next highest index.
 *
 *  XXX why not allow equal to length which would be equivalent to AppendItem?
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to insert into. Must be non-NULL.
 *  "index"
 *      Position to insert into. Must be less than List's length.
 *  "item"
 *      Address of new item to append.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "list"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_InsertItem(
        PKIX_List *list,
        PKIX_UInt32 index,
        PKIX_PL_Object *item,
        void *plContext);

/*
 * FUNCTION: PKIX_List_GetItem
 * DESCRIPTION:
 *
 *  Copies the "list"'s item at "index" into "pItem". The index counts from
 *  zero and must be less than the list's length. Increments the reference
 *  count on the returned object, if non-NULL.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to get item from. Must be non-NULL.
 *  "index"
 *      Index of list to get item from. Must be less than List's length.
 *  "pItem"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_GetItem(
        PKIX_List *list,
        PKIX_UInt32 index,
        PKIX_PL_Object **pItem,
        void *plContext);

/*
 * FUNCTION: PKIX_List_SetItem
 * DESCRIPTION:
 *
 *  Sets the item at "index" of the List pointed to by "list" with the Object
 *  pointed to by "item". The index counts from zero and must be less than the
 *  List's length. The previous entry at this index will have its reference
 *  count decremented and the new entry will have its reference count
 *  incremented.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to modify. Must be non-NULL.
 *  "index"
 *      Position in List to set. Must be less than List's length.
 *  "item"
 *      Address of Object to set at "index".
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "list"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_SetItem(
        PKIX_List *list,
        PKIX_UInt32 index,
        PKIX_PL_Object *item,
        void *plContext);

/*
 * FUNCTION: PKIX_List_DeleteItem
 *
 *  Deletes the item at "index" from the List pointed to by "list". The index
 *  counts from zero and must be less than the List's length. Note that this
 *  function does not destroy the List. It simply decrements the reference
 *  count of the item at "index" in the List, deletes that item from the list
 *  and moves all subsequent entries to a lower index in the list. If there is
 *  only a single element in the List and that element is deleted, then the
 *  List will be empty.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List to delete from. Must be non-NULL.
 *  "index"
 *      Position in List to delete. Must be less than List's length.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Not Thread Safe - assumes exclusive access to "list"
 *  (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_DeleteItem(
        PKIX_List *list,
        PKIX_UInt32 index,
        void *plContext);

/*
 * FUNCTION: PKIX_List_ReverseList
 * DESCRIPTION:
 *
 *  Creates a new List whose elements are in the reverse order as the elements
 *  of the Object pointed to by "list" and stores the copy at "pReversedList".
 *  If "list" is empty, the new reversed List will be a copy of "list".
 *  Changes to the new object will not affect the original and vice versa.
 *
 * PARAMETERS:
 *  "list"
 *      Address of List whose elements are to be reversed. Must be non-NULL.
 *  "pReversedList"
 *      Address where object pointer will be stored. Must be non-NULL.
 *  "plContext"
 *      Platform-specific context pointer.
 * THREAD SAFETY:
 *  Conditionally Thread Safe
 *      (see Thread Safety Definitions in Programmer's Guide)
 * RETURNS:
 *  Returns NULL if the function succeeds.
 *  Returns a Fatal Error if the function fails in an unrecoverable way.
 */
PKIX_Error *
PKIX_List_ReverseList(
        PKIX_List *list,
        PKIX_List **pReversedList,
        void *plContext);

#ifdef __cplusplus
}
#endif

#endif /* _PKIX_UTIL_H */