~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/asn1/asn1.h

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-25 13:04:18 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825130418-ck1i2ms384tzb9m0
Tags: 1.8.1.16+nobinonly-0ubuntu1
* New upstream release (taken from upstream CVS), LP: #254618.
* Fix MFSA 2008-35, MFSA 2008-34, MFSA 2008-33, MFSA 2008-32, MFSA 2008-31,
  MFSA 2008-30, MFSA 2008-29, MFSA 2008-28, MFSA 2008-27, MFSA 2008-25,
  MFSA 2008-24, MFSA 2008-23, MFSA 2008-22, MFSA 2008-21, MFSA 2008-26 also
  known as CVE-2008-2933, CVE-2008-2785, CVE-2008-2811, CVE-2008-2810,
  CVE-2008-2809, CVE-2008-2808, CVE-2008-2807, CVE-2008-2806, CVE-2008-2805,
  CVE-2008-2803, CVE-2008-2802, CVE-2008-2801, CVE-2008-2800, CVE-2008-2798.
* Drop 89_bz419350_attachment_306066 patch, merged upstream.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
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/
 
8
 *
 
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.
 
13
 *
 
14
 * The Original Code is the Netscape security libraries.
 
15
 *
 
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.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Alternatively, the contents of this file may be used under the terms of
 
24
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
25
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
26
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
27
 * of those above. If you wish to allow use of your version of this file only
 
28
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
29
 * use your version of this file under the terms of the MPL, indicate your
 
30
 * decision by deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
32
 * the provisions above, a recipient may use your version of this file under
 
33
 * the terms of any one of the MPL, the GPL or the LGPL.
 
34
 *
 
35
 * ***** END LICENSE BLOCK ***** */
 
36
 
 
37
#ifndef ASN1_H
 
38
#define ASN1_H
 
39
 
 
40
#ifdef DEBUG
 
41
static const char ASN1_CVS_ID[] = "@(#) $RCSfile: asn1.h,v $ $Revision: 1.3 $ $Date: 2005/01/20 02:25:44 $";
 
42
#endif /* DEBUG */
 
43
 
 
44
/*
 
45
 * asn1.h
 
46
 *
 
47
 * This file contains the ASN.1 encoder/decoder routines available
 
48
 * internally within NSS.  It's not clear right now if this file
 
49
 * will be folded into base.h or something, I just needed to get this
 
50
 * going.  At the moment, most of these routines wrap the old SEC_ASN1
 
51
 * calls.
 
52
 */
 
53
 
 
54
#ifndef ASN1T_H
 
55
#include "asn1t.h"
 
56
#endif /* ASN1T_H */
 
57
 
 
58
#ifndef BASE_H
 
59
#include "base.h"
 
60
#endif /* BASE_H */
 
61
 
 
62
PR_BEGIN_EXTERN_C
 
63
 
 
64
/*
 
65
 * nssASN1Decoder
 
66
 *
 
67
 * ... description here ...
 
68
 *
 
69
 *  nssASN1Decoder_Create (Factory/Constructor)
 
70
 *  nssASN1Decoder_Update
 
71
 *  nssASN1Decoder_Finish (Destructor)
 
72
 *  nssASN1Decoder_SetFilter
 
73
 *  nssASN1Decoder_GetFilter
 
74
 *  nssASN1Decoder_SetNotify
 
75
 *  nssASN1Decoder_GetNotify
 
76
 *
 
77
 * Debug builds only:
 
78
 *
 
79
 *  nssASN1Decoder_verify
 
80
 *
 
81
 * Related functions that aren't type methods:
 
82
 *
 
83
 *  nssASN1_Decode
 
84
 *  nssASN1_DecodeBER
 
85
 */
 
86
 
 
87
/*
 
88
 * nssASN1Decoder_Create
 
89
 *
 
90
 * This routine creates an ASN.1 Decoder, which will use the specified
 
91
 * template to decode a datastream into the specified destination
 
92
 * structure.  If the optional arena argument is non-NULL, blah blah 
 
93
 * blah.  XXX fgmr Should we include an nssASN1EncodingType argument, 
 
94
 * as a hint?  Or is each encoding distinctive?  This routine may 
 
95
 * return NULL upon error, in which case an error will have been 
 
96
 * placed upon the error stack.
 
97
 *
 
98
 * The error may be one of the following values:
 
99
 *  NSS_ERROR_NO_MEMORY
 
100
 *  NSS_ERROR_INVALID_ARENA
 
101
 *  NSS_ERROR_INVALID_POINTER
 
102
 *  ...
 
103
 *
 
104
 * Return value:
 
105
 *  NULL upon error
 
106
 *  A pointer to an ASN.1 Decoder upon success.
 
107
 */
 
108
 
 
109
NSS_EXTERN nssASN1Decoder *
 
110
nssASN1Decoder_Create
 
111
(
 
112
  NSSArena *arenaOpt,
 
113
  void *destination,
 
114
  const nssASN1Template template[]
 
115
);
 
116
 
 
117
extern const NSSError NSS_ERROR_NO_MEMORY;
 
118
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
119
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
120
 
 
121
/*
 
122
 * nssASN1Decoder_Update
 
123
 *
 
124
 * This routine feeds data to the decoder.  In the event of an error, 
 
125
 * it will place an error on the error stack and return PR_FAILURE.
 
126
 *
 
127
 * The error may be one of the following values:
 
128
 *  NSS_ERROR_NO_MEMORY
 
129
 *  NSS_ERROR_INVALID_POINTER
 
130
 *  NSS_ERROR_INVALID_ASN1DECODER
 
131
 *  NSS_ERROR_INVALID_BER
 
132
 *  ...
 
133
 *
 
134
 * Return value:
 
135
 *  PR_FAILURE upon error
 
136
 *  PR_SUCCESS upon success.
 
137
 */
 
138
 
 
139
NSS_EXTERN PRStatus
 
140
nssASN1Decoder_Update
 
141
(
 
142
  nssASN1Decoder *decoder,
 
143
  const void *data,
 
144
  PRUint32 amount
 
145
);
 
146
 
 
147
extern const NSSError NSS_ERROR_NO_MEMORY;
 
148
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
149
extern const NSSError NSS_ERROR_INVALID_BER;
 
150
 
 
151
/*
 
152
 * nssASN1Decoder_Finish
 
153
 *
 
154
 * This routine finishes the decoding and destroys the decoder.
 
155
 * In the event of an error, it will place an error on the error
 
156
 * stack and return PR_FAILURE.
 
157
 *
 
158
 * The error may be one of the following values:
 
159
 *  NSS_ERROR_INVALID_ASN1DECODER
 
160
 *
 
161
 * Return value:
 
162
 *  PR_FAILURE upon error
 
163
 *  PR_SUCCESS upon success
 
164
 */
 
165
 
 
166
NSS_EXTERN PRStatus
 
167
nssASN1Decoder_Finish
 
168
(
 
169
  nssASN1Decoder *decoder
 
170
);
 
171
 
 
172
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
173
 
 
174
/*
 
175
 * nssASN1Decoder_SetFilter
 
176
 *
 
177
 * This routine registers a callback filter routine with the decoder,
 
178
 * which will be called blah blah blah.  The specified argument will
 
179
 * be passed as-is to the filter routine.  The routine pointer may
 
180
 * be NULL, in which case no filter callback will be called.  If the
 
181
 * noStore boolean is PR_TRUE, then decoded fields will not be stored
 
182
 * in the destination structure specified when the decoder was 
 
183
 * created.  This routine returns a PRStatus value; in the event of
 
184
 * an error, it will place an error on the error stack and return
 
185
 * PR_FAILURE.
 
186
 *
 
187
 * The error may be one of the following values:
 
188
 *  NSS_ERROR_INVALID_ASN1DECODER
 
189
 *
 
190
 * Return value:
 
191
 *  PR_FAILURE upon error
 
192
 *  PR_SUCCESS upon success
 
193
 */
 
194
 
 
195
NSS_EXTERN PRStatus
 
196
nssASN1Decoder_SetFilter
 
197
(
 
198
  nssASN1Decoder *decoder,
 
199
  nssASN1DecoderFilterFunction *callback,
 
200
  void *argument,
 
201
  PRBool noStore
 
202
);
 
203
 
 
204
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
205
 
 
206
/*
 
207
 * nssASN1Decoder_GetFilter
 
208
 *
 
209
 * If the optional pCallbackOpt argument to this routine is non-null,
 
210
 * then the pointer to any callback function established for this
 
211
 * decoder with nssASN1Decoder_SetFilter will be stored at the 
 
212
 * location indicated by it.  If the optional pArgumentOpt
 
213
 * pointer is non-null, the filter's closure argument will be stored
 
214
 * there.  If the optional pNoStoreOpt pointer is non-null, the
 
215
 * noStore value specified when setting the filter will be stored
 
216
 * there.  This routine returns a PRStatus value; in the event of
 
217
 * an error it will place an error on the error stack and return
 
218
 * PR_FAILURE.
 
219
 *
 
220
 * The error may be one of the following values:
 
221
 *  NSS_ERROR_INVALID_ASN1DECODER
 
222
 *
 
223
 * Return value:
 
224
 *  PR_FAILURE upon error
 
225
 *  PR_SUCCESS upon success
 
226
 */
 
227
 
 
228
NSS_EXTERN PRStatus
 
229
nssASN1Decoder_GetFilter
 
230
(
 
231
  nssASN1Decoder *decoder,
 
232
  nssASN1DecoderFilterFunction **pCallbackOpt,
 
233
  void **pArgumentOpt,
 
234
  PRBool *pNoStoreOpt
 
235
);
 
236
 
 
237
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
238
 
 
239
/*
 
240
 * nssASN1Decoder_SetNotify
 
241
 *
 
242
 * This routine registers a callback notify routine with the decoder,
 
243
 * which will be called whenever.. The specified argument will be
 
244
 * passed as-is to the notify routine.  The routine pointer may be
 
245
 * NULL, in which case no notify routine will be called.  This routine
 
246
 * returns a PRStatus value; in the event of an error it will place
 
247
 * an error on the error stack and return PR_FAILURE.
 
248
 *
 
249
 * The error may be one of the following values:
 
250
 *  NSS_ERROR_INVALID_ASN1DECODER
 
251
 *
 
252
 * Return value:
 
253
 *  PR_FAILURE upon error
 
254
 *  PR_SUCCESS upon success
 
255
 */
 
256
 
 
257
NSS_EXTERN PRStatus
 
258
nssASN1Decoder_SetNotify
 
259
(
 
260
  nssASN1Decoder *decoder,
 
261
  nssASN1NotifyFunction *callback,
 
262
  void *argument
 
263
);
 
264
 
 
265
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
266
 
 
267
/*
 
268
 * nssASN1Decoder_GetNotify
 
269
 *
 
270
 * If the optional pCallbackOpt argument to this routine is non-null,
 
271
 * then the pointer to any callback function established for this
 
272
 * decoder with nssASN1Decoder_SetNotify will be stored at the 
 
273
 * location indicated by it.  If the optional pArgumentOpt pointer is
 
274
 * non-null, the filter's closure argument will be stored there.
 
275
 * This routine returns a PRStatus value; in the event of an error it
 
276
 * will place an error on the error stack and return PR_FAILURE.
 
277
 *
 
278
 * The error may be one of the following values:
 
279
 *  NSS_ERROR_INVALID_ASN1DECODER
 
280
 *
 
281
 * Return value:
 
282
 *  PR_FAILURE upon error
 
283
 *  PR_SUCCESS upon success
 
284
 */
 
285
 
 
286
NSS_EXTERN PRStatus
 
287
nssASN1Decoder_GetNotify
 
288
(
 
289
  nssASN1Decoder *decoder,
 
290
  nssASN1NotifyFunction **pCallbackOpt,
 
291
  void **pArgumentOpt
 
292
);
 
293
 
 
294
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
295
 
 
296
/*
 
297
 * nssASN1Decoder_verify
 
298
 *
 
299
 * This routine is only available in debug builds.
 
300
 *
 
301
 * If the specified pointer is a valid pointer to an nssASN1Decoder
 
302
 * object, this routine will return PR_SUCCESS.  Otherwise, it will 
 
303
 * put an error on the error stack and return PR_FAILURE.
 
304
 *
 
305
 * The error may be one of the following values:
 
306
 *  NSS_ERROR_INVALID_ASN1DECODER
 
307
 *
 
308
 * Return value:
 
309
 *  PR_FAILURE upon error
 
310
 *  PR_SUCCESS upon success
 
311
 */
 
312
 
 
313
#ifdef DEBUG
 
314
NSS_EXTERN PRStatus
 
315
nssASN1Decoder_verify
 
316
(
 
317
  nssASN1Decoder *decoder
 
318
);
 
319
 
 
320
extern const NSSError NSS_ERROR_INVALID_ASN1DECODER;
 
321
#endif /* DEBUG */
 
322
 
 
323
/*
 
324
 * nssASN1_Decode
 
325
 *
 
326
 * This routine will decode the specified data into the specified
 
327
 * destination structure, as specified by the specified template.
 
328
 * This routine returns a PRStatus value; in the event of an error
 
329
 * it will place an error on the error stack and return PR_FAILURE.
 
330
 *
 
331
 * The error may be one of the following values:
 
332
 *  NSS_ERROR_NO_MEMORY
 
333
 *  NSS_ERROR_INVALID_ARENA
 
334
 *  NSS_ERROR_INVALID_POINTER
 
335
 *  NSS_ERROR_INVALID_BER
 
336
 *
 
337
 * Return value:
 
338
 *  PR_FAILURE upon error
 
339
 *  PR_SUCCESS upon success
 
340
 */
 
341
 
 
342
NSS_EXTERN PRStatus
 
343
nssASN1_Decode
 
344
(
 
345
  NSSArena *arenaOpt,
 
346
  void *destination,
 
347
  const nssASN1Template template[],
 
348
  const void *berData,
 
349
  PRUint32 amount
 
350
);
 
351
 
 
352
extern const NSSError NSS_ERROR_NO_MEMORY;
 
353
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
354
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
355
extern const NSSError NSS_ERROR_INVALID_BER;
 
356
 
 
357
/*
 
358
 * nssASN1_DecodeBER
 
359
 *
 
360
 * This routine will decode the data in the specified NSSBER
 
361
 * into the destination structure, as specified by the template.
 
362
 * This routine returns a PRStatus value; in the event of an error
 
363
 * it will place an error on the error stack and return PR_FAILURE.
 
364
 *
 
365
 * The error may be one of the following values:
 
366
 *  NSS_ERROR_NO_MEMORY
 
367
 *  NSS_ERROR_INVALID_ARENA
 
368
 *  NSS_ERROR_INVALID_POINTER
 
369
 *  NSS_ERROR_INVALID_NSSBER
 
370
 *  NSS_ERROR_INVALID_BER
 
371
 *
 
372
 * Return value:
 
373
 *  PR_FAILURE upon error
 
374
 *  PR_SUCCESS upon success
 
375
 */
 
376
 
 
377
NSS_EXTERN PRStatus
 
378
nssASN1_DecodeBER
 
379
(
 
380
  NSSArena *arenaOpt,
 
381
  void *destination,
 
382
  const nssASN1Template template[],
 
383
  const NSSBER *data
 
384
);
 
385
 
 
386
extern const NSSError NSS_ERROR_NO_MEMORY;
 
387
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
388
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
389
extern const NSSError NSS_ERROR_INVALID_BER;
 
390
 
 
391
/*
 
392
 * nssASN1Encoder
 
393
 *
 
394
 * ... description here ...
 
395
 *
 
396
 *  nssASN1Encoder_Create (Factory/Constructor)
 
397
 *  nssASN1Encoder_Update
 
398
 *  nssASN1Encoder_Finish (Destructor)
 
399
 *  nssASN1Encoder_SetNotify
 
400
 *  nssASN1Encoder_GetNotify
 
401
 *  nssASN1Encoder_SetStreaming
 
402
 *  nssASN1Encoder_GetStreaming
 
403
 *  nssASN1Encoder_SetTakeFromBuffer
 
404
 *  nssASN1Encoder_GetTakeFromBuffer
 
405
 *
 
406
 * Debug builds only:
 
407
 *
 
408
 *  nssASN1Encoder_verify
 
409
 *
 
410
 * Related functions that aren't type methods:
 
411
 *
 
412
 *  nssASN1_Encode
 
413
 *  nssASN1_EncodeItem
 
414
 */
 
415
 
 
416
/*
 
417
 * nssASN1Encoder_Create
 
418
 *
 
419
 * This routine creates an ASN.1 Encoder, blah blah blah.  This 
 
420
 * may return NULL upon error, in which case an error will have been
 
421
 * placed on the error stack.
 
422
 *
 
423
 * The error may be one of the following values:
 
424
 *  NSS_ERROR_NO_MEMORY
 
425
 *  NSS_ERROR_INVALID_ARENA
 
426
 *  NSS_ERROR_INVALID_POINTER
 
427
 *  NSS_ERROR_ENCODING_NOT_SUPPORTED
 
428
 *  ...
 
429
 *
 
430
 * Return value:
 
431
 *  NULL upon error
 
432
 *  A pointer to an ASN.1 Encoder upon success
 
433
 */
 
434
 
 
435
NSS_EXTERN nssASN1Encoder *
 
436
nssASN1Encoder_Create
 
437
(
 
438
  const void *source,
 
439
  const nssASN1Template template[],
 
440
  NSSASN1EncodingType encoding,
 
441
  nssASN1EncoderWriteFunction *sink,
 
442
  void *argument
 
443
);
 
444
 
 
445
extern const NSSError NSS_ERROR_NO_MEMORY;
 
446
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
447
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
448
extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
 
449
 
 
450
/*
 
451
 * nssASN1Encoder_Update
 
452
 *
 
453
 * The error may be one of the following values:
 
454
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
455
 *  NSS_ERROR_INVALID_POINTER
 
456
 *
 
457
 * Return value:
 
458
 *  PR_FAILURE upon error
 
459
 *  PR_SUCCESS upon success
 
460
 */
 
461
 
 
462
NSS_EXTERN PRStatus
 
463
nssASN1Encoder_Update
 
464
(
 
465
  nssASN1Encoder *encoder,
 
466
  const void *data,
 
467
  PRUint32 length
 
468
);
 
469
 
 
470
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
471
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
472
 
 
473
/*
 
474
 * nssASN1Encoder_Finish
 
475
 *
 
476
 * Destructor.
 
477
 *
 
478
 * The error may be one of the following values:
 
479
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
480
 *
 
481
 * Return value:
 
482
 *  PR_FAILURE upon error
 
483
 *  PR_SUCCESS upon success
 
484
 */
 
485
 
 
486
NSS_EXTERN PRStatus
 
487
nssASN1Encoder_Finish
 
488
(
 
489
  nssASN1Encoder *encoder
 
490
);
 
491
 
 
492
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
493
 
 
494
/*
 
495
 * nssASN1Encoder_SetNotify
 
496
 *
 
497
 * This routine registers a callback notify routine with the encoder,
 
498
 * which will be called whenever.. The specified argument will be
 
499
 * passed as-is to the notify routine.  The routine pointer may be
 
500
 * NULL, in which case no notify routine will be called.  This routine
 
501
 * returns a PRStatus value; in the event of an error it will place
 
502
 * an error on the error stack and return PR_FAILURE.
 
503
 *
 
504
 * The error may be one of the following values:
 
505
 *  NSS_ERROR_INVALID_ASN1DECODER
 
506
 *
 
507
 * Return value:
 
508
 *  PR_FAILURE upon error
 
509
 *  PR_SUCCESS upon success
 
510
 */
 
511
 
 
512
NSS_EXTERN PRStatus
 
513
nssASN1Encoder_SetNotify
 
514
(
 
515
  nssASN1Encoder *encoder,
 
516
  nssASN1NotifyFunction *callback,
 
517
  void *argument
 
518
);
 
519
 
 
520
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
521
 
 
522
/*
 
523
 * nssASN1Encoder_GetNotify
 
524
 *
 
525
 * If the optional pCallbackOpt argument to this routine is non-null,
 
526
 * then the pointer to any callback function established for this
 
527
 * decoder with nssASN1Encoder_SetNotify will be stored at the 
 
528
 * location indicated by it.  If the optional pArgumentOpt pointer is
 
529
 * non-null, the filter's closure argument will be stored there.
 
530
 * This routine returns a PRStatus value; in the event of an error it
 
531
 * will place an error on the error stack and return PR_FAILURE.
 
532
 *
 
533
 * The error may be one of the following values:
 
534
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
535
 *
 
536
 * Return value:
 
537
 *  PR_FAILURE upon error
 
538
 *  PR_SUCCESS upon success
 
539
 */
 
540
 
 
541
NSS_EXTERN PRStatus
 
542
nssASN1Encoder_GetNotify
 
543
(
 
544
  nssASN1Encoder *encoder,
 
545
  nssASN1NotifyFunction **pCallbackOpt,
 
546
  void **pArgumentOpt
 
547
);
 
548
 
 
549
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
550
 
 
551
/*
 
552
 * nssASN1Encoder_SetStreaming
 
553
 *
 
554
 * 
 
555
 * The error may be one of the following values:
 
556
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
557
 *
 
558
 * Return value:
 
559
 *  PR_FAILURE upon error
 
560
 *  PR_SUCCESS upon success
 
561
 */
 
562
 
 
563
NSS_EXTERN PRStatus
 
564
nssASN1Encoder_SetStreaming
 
565
(
 
566
  nssASN1Encoder *encoder,
 
567
  PRBool streaming
 
568
);
 
569
 
 
570
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
571
 
 
572
/*
 
573
 * nssASN1Encoder_GetStreaming
 
574
 *
 
575
 *
 
576
 * The error may be one of the following values:
 
577
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
578
 *  NSS_ERROR_INVALID_POINTER
 
579
 *
 
580
 * Return value:
 
581
 *  PR_FAILURE upon error
 
582
 *  PR_SUCCESS upon success
 
583
 */
 
584
 
 
585
NSS_EXTERN PRStatus
 
586
nssASN1Encoder_GetStreaming
 
587
(
 
588
  nssASN1Encoder *encoder,
 
589
  PRBool *pStreaming
 
590
);
 
591
 
 
592
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
593
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
594
 
 
595
/*
 
596
 * nssASN1Encoder_SetTakeFromBuffer
 
597
 *
 
598
 *
 
599
 * The error may be one of the following values:
 
600
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
601
 *
 
602
 * Return value:
 
603
 *  PR_FAILURE upon error
 
604
 *  PR_SUCCESS upon success
 
605
 */
 
606
 
 
607
NSS_EXTERN PRStatus
 
608
nssASN1Encoder_SetTakeFromBuffer
 
609
(
 
610
  nssASN1Encoder *encoder,
 
611
  PRBool takeFromBuffer
 
612
);
 
613
 
 
614
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
615
 
 
616
/*
 
617
 * nssASN1Encoder_GetTakeFromBuffer
 
618
 *
 
619
 *
 
620
 * The error may be one of the following values:
 
621
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
622
 *  NSS_ERROR_INVALID_POINTER
 
623
 *
 
624
 * Return value:
 
625
 *  PR_FAILURE upon error
 
626
 *  PR_SUCCESS upon success
 
627
 */
 
628
 
 
629
NSS_EXTERN PRStatus
 
630
nssASN1Encoder_GetTakeFromBuffer
 
631
(
 
632
  nssASN1Encoder *encoder,
 
633
  PRBool *pTakeFromBuffer
 
634
);
 
635
 
 
636
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
637
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
638
 
 
639
/*
 
640
 * nssASN1Encoder_verify
 
641
 *
 
642
 * This routine is only available in debug builds.
 
643
 *
 
644
 * If the specified pointer is a valid pointer to an nssASN1Encoder
 
645
 * object, this routine will return PR_SUCCESS.  Otherwise, it will 
 
646
 * put an error on the error stack and return PR_FAILURE.
 
647
 *
 
648
 * The error may be one of the following values:
 
649
 *  NSS_ERROR_INVALID_ASN1ENCODER
 
650
 *
 
651
 * Return value:
 
652
 *  PR_FAILURE upon error
 
653
 *  PR_SUCCESS upon success
 
654
 */
 
655
 
 
656
#ifdef DEBUG
 
657
NSS_EXTERN PRStatus
 
658
nssASN1Encoder_verify
 
659
(
 
660
  nssASN1Encoder *encoder
 
661
);
 
662
 
 
663
extern const NSSError NSS_ERROR_INVALID_ASN1ENCODER;
 
664
#endif /* DEBUG */
 
665
 
 
666
/*
 
667
 * nssASN1_Encode
 
668
 *
 
669
 * 
 
670
 * The error may be one of the following values:
 
671
 *  NSS_ERROR_NO_MEMORY
 
672
 *  NSS_ERROR_INVALID_ARENA
 
673
 *  NSS_ERROR_INVALID_POINTER
 
674
 *  NSS_ERROR_ENCODING_NOT_SUPPORTED
 
675
 *  ...
 
676
 *
 
677
 * Return value:
 
678
 *  PR_FAILURE upon error
 
679
 *  PR_SUCCESS upon success
 
680
 */
 
681
 
 
682
NSS_EXTERN PRStatus
 
683
nssASN1_Encode
 
684
(
 
685
  const void *source,
 
686
  const nssASN1Template template[],
 
687
  NSSASN1EncodingType encoding,
 
688
  nssASN1EncoderWriteFunction *sink,
 
689
  void *argument
 
690
);
 
691
 
 
692
extern const NSSError NSS_ERROR_NO_MEMORY;
 
693
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
694
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
695
extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
 
696
 
 
697
/*
 
698
 * nssASN1_EncodeItem
 
699
 *
 
700
 * There must be a better name.  If the optional arena argument is
 
701
 * non-null, it'll be used for the space.  If the optional rvOpt is
 
702
 * non-null, it'll be the return value-- if it is null, a new one
 
703
 * will be allocated.
 
704
 *
 
705
 * The error may be one of the following values:
 
706
 *  NSS_ERROR_NO_MEMORY
 
707
 *  NSS_ERROR_INVALID_ARENA
 
708
 *  NSS_ERROR_INVALID_POINTER
 
709
 *  NSS_ERROR_ENCODING_NOT_SUPPORTED
 
710
 *
 
711
 * Return value:
 
712
 *  NULL upon error
 
713
 *  A valid pointer to an NSSDER upon success
 
714
 */
 
715
 
 
716
NSS_EXTERN NSSDER *
 
717
nssASN1_EncodeItem
 
718
(
 
719
  NSSArena *arenaOpt,
 
720
  NSSDER *rvOpt,
 
721
  const void *source,
 
722
  const nssASN1Template template[],
 
723
  NSSASN1EncodingType encoding
 
724
);
 
725
 
 
726
extern const NSSError NSS_ERROR_NO_MEMORY;
 
727
extern const NSSError NSS_ERROR_INVALID_ARENA;
 
728
extern const NSSError NSS_ERROR_INVALID_POINTER;
 
729
extern const NSSError NSS_ERROR_ENCODING_NOT_SUPPORTED;
 
730
 
 
731
/*
 
732
 * Other basic types' encoding and decoding helper functions:
 
733
 *
 
734
 *  nssASN1_CreatePRUint32FromBER
 
735
 *  nssASN1_GetDERFromPRUint32
 
736
 *  nssASN1_CreatePRInt32FromBER
 
737
 *  nssASN1_GetDERFromPRInt32
 
738
 * ..etc..
 
739
 */
 
740
 
 
741
/*
 
742
 * nssASN1_CreatePRUint32FromBER
 
743
 *
 
744
 */
 
745
 
 
746
NSS_EXTERN PRStatus
 
747
nssASN1_CreatePRUint32FromBER
 
748
(
 
749
  NSSBER *encoded,
 
750
  PRUint32 *pResult
 
751
);
 
752
 
 
753
/*
 
754
 * nssASN1_GetDERFromPRUint32
 
755
 *
 
756
 */
 
757
 
 
758
NSS_EXTERN NSSDER *
 
759
nssASN1_GetDERFromPRUint32
 
760
(
 
761
  NSSArena *arenaOpt,
 
762
  NSSDER *rvOpt,
 
763
  PRUint32 value
 
764
);
 
765
 
 
766
/*
 
767
 * nssASN1_CreatePRInt32FromBER
 
768
 *
 
769
 */
 
770
 
 
771
NSS_EXTERN PRStatus
 
772
nssASN1_CreatePRInt32FromBER
 
773
(
 
774
  NSSBER *encoded,
 
775
  PRInt32 *pResult
 
776
);
 
777
 
 
778
/*
 
779
 * nssASN1_GetDERFromPRInt32
 
780
 *
 
781
 */
 
782
 
 
783
NSS_EXTERN NSSDER *
 
784
nssASN1_GetDERFromPRInt32
 
785
(
 
786
  NSSArena *arenaOpt,
 
787
  NSSDER *rvOpt,
 
788
  PRInt32 value
 
789
);
 
790
 
 
791
/*
 
792
 * Builtin templates
 
793
 */
 
794
 
 
795
/*
 
796
 * Generic Templates
 
797
 * One for each of the simple types, plus a special one for ANY, plus:
 
798
 *      - a pointer to each one of those
 
799
 *      - a set of each one of those
 
800
 *
 
801
 * Note that these are alphabetical (case insensitive); please add new
 
802
 * ones in the appropriate place.
 
803
 */
 
804
 
 
805
extern const nssASN1Template *nssASN1Template_Any;
 
806
extern const nssASN1Template *nssASN1Template_BitString;
 
807
extern const nssASN1Template *nssASN1Template_BMPString;
 
808
extern const nssASN1Template *nssASN1Template_Boolean;
 
809
extern const nssASN1Template *nssASN1Template_Enumerated;
 
810
extern const nssASN1Template *nssASN1Template_GeneralizedTime;
 
811
extern const nssASN1Template *nssASN1Template_IA5String;
 
812
extern const nssASN1Template *nssASN1Template_Integer;
 
813
extern const nssASN1Template *nssASN1Template_Null;
 
814
extern const nssASN1Template *nssASN1Template_ObjectID;
 
815
extern const nssASN1Template *nssASN1Template_OctetString;
 
816
extern const nssASN1Template *nssASN1Template_PrintableString;
 
817
extern const nssASN1Template *nssASN1Template_T61String;
 
818
extern const nssASN1Template *nssASN1Template_UniversalString;
 
819
extern const nssASN1Template *nssASN1Template_UTCTime;
 
820
extern const nssASN1Template *nssASN1Template_UTF8String;
 
821
extern const nssASN1Template *nssASN1Template_VisibleString;
 
822
 
 
823
extern const nssASN1Template *nssASN1Template_PointerToAny;
 
824
extern const nssASN1Template *nssASN1Template_PointerToBitString;
 
825
extern const nssASN1Template *nssASN1Template_PointerToBMPString;
 
826
extern const nssASN1Template *nssASN1Template_PointerToBoolean;
 
827
extern const nssASN1Template *nssASN1Template_PointerToEnumerated;
 
828
extern const nssASN1Template *nssASN1Template_PointerToGeneralizedTime;
 
829
extern const nssASN1Template *nssASN1Template_PointerToIA5String;
 
830
extern const nssASN1Template *nssASN1Template_PointerToInteger;
 
831
extern const nssASN1Template *nssASN1Template_PointerToNull;
 
832
extern const nssASN1Template *nssASN1Template_PointerToObjectID;
 
833
extern const nssASN1Template *nssASN1Template_PointerToOctetString;
 
834
extern const nssASN1Template *nssASN1Template_PointerToPrintableString;
 
835
extern const nssASN1Template *nssASN1Template_PointerToT61String;
 
836
extern const nssASN1Template *nssASN1Template_PointerToUniversalString;
 
837
extern const nssASN1Template *nssASN1Template_PointerToUTCTime;
 
838
extern const nssASN1Template *nssASN1Template_PointerToUTF8String;
 
839
extern const nssASN1Template *nssASN1Template_PointerToVisibleString;
 
840
 
 
841
extern const nssASN1Template *nssASN1Template_SetOfAny;
 
842
extern const nssASN1Template *nssASN1Template_SetOfBitString;
 
843
extern const nssASN1Template *nssASN1Template_SetOfBMPString;
 
844
extern const nssASN1Template *nssASN1Template_SetOfBoolean;
 
845
extern const nssASN1Template *nssASN1Template_SetOfEnumerated;
 
846
extern const nssASN1Template *nssASN1Template_SetOfGeneralizedTime;
 
847
extern const nssASN1Template *nssASN1Template_SetOfIA5String;
 
848
extern const nssASN1Template *nssASN1Template_SetOfInteger;
 
849
extern const nssASN1Template *nssASN1Template_SetOfNull;
 
850
extern const nssASN1Template *nssASN1Template_SetOfObjectID;
 
851
extern const nssASN1Template *nssASN1Template_SetOfOctetString;
 
852
extern const nssASN1Template *nssASN1Template_SetOfPrintableString;
 
853
extern const nssASN1Template *nssASN1Template_SetOfT61String;
 
854
extern const nssASN1Template *nssASN1Template_SetOfUniversalString;
 
855
extern const nssASN1Template *nssASN1Template_SetOfUTCTime;
 
856
extern const nssASN1Template *nssASN1Template_SetOfUTF8String;
 
857
extern const nssASN1Template *nssASN1Template_SetOfVisibleString;
 
858
 
 
859
/*
 
860
 *
 
861
 */
 
862
 
 
863
NSS_EXTERN NSSUTF8 *
 
864
nssUTF8_CreateFromBER
 
865
(
 
866
  NSSArena *arenaOpt,
 
867
  nssStringType type,
 
868
  NSSBER *berData
 
869
);
 
870
 
 
871
NSS_EXTERN NSSDER *
 
872
nssUTF8_GetDEREncoding
 
873
(
 
874
  NSSArena *arenaOpt,
 
875
  /* Should have an NSSDER *rvOpt */
 
876
  nssStringType type,
 
877
  const NSSUTF8 *string
 
878
);
 
879
 
 
880
PR_END_EXTERN_C
 
881
 
 
882
#endif /* ASN1_H */