]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
1 | /* |
2 | * The contents of this file are subject to the Mozilla Public | |
3 | * License Version 1.1 (the "License"); you may not use this file | |
4 | * except in compliance with the License. You may obtain a copy of | |
5 | * the License at http://www.mozilla.org/MPL/ | |
6 | * | |
7 | * Software distributed under the License is distributed on an "AS | |
8 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
9 | * implied. See the License for the specific language governing | |
10 | * rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is the Netscape security libraries. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape | |
15 | * Communications Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1994-2000 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | * Alternatively, the contents of this file may be used under the | |
22 | * terms of the GNU General Public License Version 2 or later (the | |
23 | * "GPL"), in which case the provisions of the GPL are applicable | |
24 | * instead of those above. If you wish to allow use of your | |
25 | * version of this file only under the terms of the GPL and not to | |
26 | * allow others to use your version of this file under the MPL, | |
27 | * indicate your decision by deleting the provisions above and | |
28 | * replace them with the notice and other provisions required by | |
29 | * the GPL. If you do not delete the provisions above, a recipient | |
30 | * may use your version of this file under either the MPL or the | |
31 | * GPL. | |
32 | */ | |
33 | ||
34 | /* | |
35 | * Private (SPI) types libsecurity_asn1.h. | |
36 | */ | |
37 | ||
38 | #ifndef _SECASN1T_H_ | |
39 | #define _SECASN1T_H_ | |
40 | ||
41 | #include <CoreFoundation/CFBase.h> /* Boolean */ | |
42 | #include <sys/types.h> | |
43 | #include <Security/SecAsn1Types.h> /* public types */ | |
44 | ||
45 | ||
46 | /* default size used for allocation of encoding/decoding stuff */ | |
47 | #define SEC_ASN1_DEFAULT_ARENA_SIZE (2048) | |
48 | ||
49 | /* | |
50 | * Tempalte flags we don't export in the public API in SecAsn1Types.h | |
51 | */ | |
52 | #define SEC_ASN1_MAY_STREAM 0x40000 /* field or one of its sub-fields may | |
53 | * stream in and so should encode as | |
54 | * indefinite-length when streaming | |
55 | * has been indicated; only for | |
56 | * encoding */ | |
57 | #define SEC_ASN1_NO_STREAM 0X200000 /* This entry will not stream | |
58 | * even if the sub-template says | |
59 | * streaming is possible. Helps | |
60 | * to solve ambiguities with potential | |
61 | * streaming entries that are | |
62 | * optional */ | |
63 | ||
64 | /* Maximum depth of nested SEQUENCEs and SETs */ | |
65 | #define SEC_ASN1D_MAX_DEPTH 32 | |
66 | ||
67 | #define SEC_ASN1_GET(x) x | |
68 | #define SEC_ASN1_SUB(x) x | |
69 | #define SEC_ASN1_XTRN 0 | |
70 | #define SEC_ASN1_MKSUB(x) | |
71 | ||
72 | #define SEC_ASN1_CHOOSER_DECLARE(x) \ | |
73 | extern const SecAsn1Template * NSS_Get_##x (void *arg, Boolean enc); | |
74 | ||
75 | #define SEC_ASN1_CHOOSER_IMPLEMENT(x) \ | |
76 | const SecAsn1Template * NSS_Get_##x(void * arg, Boolean enc) \ | |
77 | { return x; } | |
78 | ||
79 | /* | |
80 | ** Opaque object used by the decoder to store state. | |
81 | */ | |
82 | typedef struct sec_DecoderContext_struct SEC_ASN1DecoderContext; | |
83 | ||
84 | /* | |
85 | ** Opaque object used by the encoder to store state. | |
86 | */ | |
87 | typedef struct sec_EncoderContext_struct SEC_ASN1EncoderContext; | |
88 | ||
89 | /* | |
90 | * This is used to describe to a filter function the bytes that are | |
91 | * being passed to it. This is only useful when the filter is an "outer" | |
92 | * one, meaning it expects to get *all* of the bytes not just the | |
93 | * contents octets. | |
94 | */ | |
95 | typedef enum { | |
96 | SEC_ASN1_Identifier = 0, | |
97 | SEC_ASN1_Length = 1, | |
98 | SEC_ASN1_Contents = 2, | |
99 | SEC_ASN1_EndOfContents = 3 | |
100 | } SEC_ASN1EncodingPart; | |
101 | ||
102 | /* | |
103 | * Type of the function pointer used either for decoding or encoding, | |
104 | * when doing anything "funny" (e.g. manipulating the data stream) | |
105 | */ | |
106 | typedef void (* SEC_ASN1NotifyProc)(void *arg, Boolean before, | |
107 | void *dest, int real_depth); | |
108 | ||
109 | /* | |
110 | * Type of the function pointer used for grabbing encoded bytes. | |
111 | * This can be used during either encoding or decoding, as follows... | |
112 | * | |
113 | * When decoding, this can be used to filter the encoded bytes as they | |
114 | * are parsed. This is what you would do if you wanted to process the data | |
115 | * along the way (like to decrypt it, or to perform a hash on it in order | |
116 | * to do a signature check later). See SEC_ASN1DecoderSetFilterProc(). | |
117 | * When processing only part of the encoded bytes is desired, you "watch" | |
118 | * for the field(s) you are interested in with a "notify proc" (see | |
119 | * SEC_ASN1DecoderSetNotifyProc()) and for even finer granularity (e.g. to | |
120 | * ignore all by the contents bytes) you pay attention to the "data_kind" | |
121 | * parameter. | |
122 | * | |
123 | * When encoding, this is the specification for the output function which | |
124 | * will receive the bytes as they are encoded. The output function can | |
125 | * perform any postprocessing necessary (like hashing (some of) the data | |
126 | * to create a digest that gets included at the end) as well as shoving | |
127 | * the data off wherever it needs to go. (In order to "tune" any processing, | |
128 | * you can set a "notify proc" as described above in the decoding case.) | |
129 | * | |
130 | * The parameters: | |
131 | * - "arg" is an opaque pointer that you provided at the same time you | |
132 | * specified a function of this type | |
133 | * - "data" is a buffer of length "len", containing the encoded bytes | |
134 | * - "depth" is how deep in a nested encoding we are (it is not usually | |
135 | * valuable, but can be useful sometimes so I included it) | |
136 | * - "data_kind" tells you if these bytes are part of the ASN.1 encoded | |
137 | * octets for identifier, length, contents, or end-of-contents | |
138 | */ | |
139 | typedef void (* SEC_ASN1WriteProc)(void *arg, | |
140 | const char *data, size_t len, | |
141 | int depth, SEC_ASN1EncodingPart data_kind); | |
142 | ||
143 | #endif /* _SECASN1T_H_ */ |